|
43533
|
1587
|
42
|
2026-05-14T12:57:10.389146+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763430389_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43527
|
1587
|
38
|
2026-05-14T12:56:49.746409+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763409746_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
43525
|
NULL
|
NULL
|
NULL
|
|
43526
|
1588
|
22
|
2026-05-14T12:56:48.650186+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763408650_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.38397607,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-3609238797962493755
|
-8744686341396387260
|
app_switch
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43525
|
1587
|
37
|
2026-05-14T12:56:48.650186+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763408650_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-3992299231040143819
|
-8744686324216518076
|
app_switch
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43486
|
1588
|
7
|
2026-05-14T12:54:20.331110+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763260331_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.38397607,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42586437,"top":0.12210695,"width":0.33178192,"height":0.87789303},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43485
|
1588
|
6
|
2026-05-14T12:54:17.585858+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763257585_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PnostormroledeyFV faVsco.js#12077 on JY-20903-upda PnostormroledeyFV faVsco.js#12077 on JY-20903-update_activity-stageyUserinvitationdro.onp) CheckAndRetryRemoteMatch.php= custom.logscratch. &.ison=laravel.logA SF [jiminny@localhost]& HS_local [jiminny@localhost]console [PRODI© SyncPlanhat.phpO syncuserrllot.onp© ValidateSendingMessage.pCo kematchactviyoncrmoojectbetach.ong© ActivitiesMatchCrmCommand.php X ©MatchActivityCrmData.php© ImportParticipants.phpA console (EU]tiò accounts [EU]ii stages (EU]tid teams [EU]ImporbotkecoraingJoo.org© Activity.php x© FixActivitiesOpportunity.php© Opportunity.phpclass Acclvicleshacchurmcommana excenas commana[AAVValladtesenaingnotricatio> D WebhookE.gitkeep© ChangeLogContextCorrelatiov @ Mailv @ Activitiesc) exportLink.php© MailBoxFailedToConnect.p) smskeceivea.php© SmsRelavFailed.phpc)Trackkestored.onoCalendars>D crmReports(c) Mailable.ohoModelsM ActivityAskAnvthindm ConnectionM Contracts,M Crm(c) BusinessProcess.pnp© Configuration.php© ContactRole.php© Field.php© FieldData.phpc rielavalue.onpc Layout.onpc) Lavoutcnulv.onoc) Loq.phpC) Profile.phpC) RecordTvpe.phpc) SvncBatch.php> C7 ElasticSearch→→ FeatureM Opportunitv> M Particioant7 Plavbackithem:M Plavlist)N ScorecardMWebhook109111(C) Activitv nhn.oubulc tunccion nanaled.Sactivityids = sactivity->qetidou^} else {Steam = Team::+indcsteamd)*if (Steam === nulb) 1Sthis->error( strina: "Cannot find team."):2LOS,return CommandAzias: : FATLURE:Sthis->info( string: Steam->getName)'' | matching activities from ' • $from.' to' . $to);Sactivities = Activity::select( columns: 'activities.id')->join( table:-wnle ro collUitinconetezinieioperator:'=', $team->getIdo)'activities.created_at', [$from, $tol):1=' second: "usenc.id')if (SmatchFrom0therCrm) {itawtloweWalonoueeiluieeln: 'activities.crm_configuration_id', operator: '!=', Steam->getCrmConfi, 2118SactivityIds = Sactivities->pluck( column: 'id'):Sthis->info( string: 'Found activities: ' . SactivityIds->countO):if ( Sthis->confirm( question: "Do vou want to continue?') 'cneo2126foreach (SactivitvIds as $activitvld) {Sthis->disoatchonew Matchactivitvermbatalaint)Sactivitvid.fromConfiguration: SmatchFrom0therCrm ? $team->getCrmConfiguration : null,|[CREDIT_CARD]|2137213821392140return CommandALias::SUCCESS;21422144A console [STAGING]class Activity extends Model implements44 4169 M4 M102 .4 ^VOUDLICtunction updateActivityCrmData(array Srecords): void(C) A Promnt nhr21442147if (Sthis-›stage_id === null && $stage) 1$this-›stage_id = $stage->id;Sthic-scaved}elseif (Sstrategy== Updaceurmuarabyscracegy::concact)// Also update the parent activity if required, checking we don't create a mixed lead/account record.Sch1s->lead 10 = null:if (Sthis-›stage && $this->stage->getType• === Stage::TYPE LEAD) {Sch1s->stage 10 = null:II Don't trust previous matched account id as it might have been changed in the CRMif (Saccount && Saccount->id !== Sthis->account id) {Sthis->account_ 1d = Saccount->1d:if (Sopportunity && $this->opportunity_id !== $opportunity->id) {Sthis->onnortunitv id = Sonnortunitv->id:// Reset stage_id when opportunity changes to avoid stale stage from previous opportunity matchSthis->stade id = Sstaged->id.if (Sthis->stage_id === null && $stage) 1Sthic-sctaae id = Sctane-sid.if (Sopportunity && $this->value !== Sopportunity->value) {Cthic-svalme = Sooportunzcy»>value// Always set contact id when available, regardless of account id statusif (Sthis->contact_id === null && Scontact) {Sthis->contact_id = Scontact->idSthis->saveo:} elseif (Sstrategy == UpdateCrmDataByStrategv::Account &s $this->account_id === null) {I/ Also undate the narent activity if required, checking we don't create a mixed lead/account recordiSthis->lead 1d = null.if (Sthis->stage && Sthis->stage->getTvne() === Stage::TYPE LEAD) {Sthis->stage id = null:• Inu 14 May 10.04.14AskJiminnyReportActivityServiceTest vcascadePipedrive SDK EvaluaActivity Stage DiscrerImport CRM Activity T+0 ..Flow 1: Calendar Import - Participant ProcessingLocation: ImportParticipants::processuine S/ When: During calendar event impon wnen participants change or it'sahew acuvily triggerParticinant chandes detected durina imoort.• New activity being created from calendar Path: processParticipants() → updateActivityCrmData()Flow 2: Calencar moor - Wraoper MernodLocation: TmnortParticinants::undateActivitvCrmData() (line 121) When: After CRM lookun comnletes. beforelogging the update Trigger: Called from Flow 1's process() method Path: Wraps the Activity model's method withloggingFlow 3: Conference CRM RefreshLocation: ImportParticipants::refreshCrmData() (line 192) When: After a meeting finishes, when validatingparticipants and running CRM matching Trigger: ConferenceCrmMatcherJob dispatches this to refresh CRM data Path:ConferenceCrmMatcherJob → refreshCrmData( → particinantCrmLookun) → undateActivitvCrmbata(0)Clow 1. CPM Activity Service UindateLocation: CrmActivitvService::updateCrmData line 89 When: When explicitly updatina CRM data for an activity andits narticinants Triaaer. Manual CRM data undates or sunc onerations Path: undateParticinantsCrmlata() → undateActlSlow 5: Event Listener - Maich CRM ObiectLocation• MatchGrm0biect.«handlel) (line 112) When. When a coftnhone connestion onens or a narticinant inine• Connections Onened - dispatched when softohone connection obens (SoftPhoneManader lines 637, 672Dartscinantel loinod - disnatched whon narticinant inine conforenco (Twilia conferance evente) Dath- Gvent aMatchCrmObiect listener → CRM lookup → undateActivitvCrmData))Slow 6. Event Listener - Undate CRM DatalLocation: UpdateCrmData: : handle() (line 74) When: When a conference starts Triggered by event:conforoncoel Ctartodi - dienatched when conforando ctarte (Coccione| Startad lina 26 Twilin evente) DatheConferenceStarted event → UpdateCrmData listener → updateParticipantsCrmData() → updateActivityCrmDatafal .So all are only up to the poitn activity actual_end_data. Or is there something also later. Reveiw again and explain flowaThoucht for 1s >keас crmacuivilyservice.onpThought for 1s>Searched CrmActivityService,*updateCrmData in apoRead MatchActivitvCrmData.ohvThought for 1s ›Searched MatchActivityCrmData in appAM GMT+3.led weekly usage guota is exhausted. Purchase extra usage to continue using premium models. Quota resets May 17, 11:00Ask anvthina (84-L1« CodeSWE-16WN Windsurf Teams 2126-14UITF.RPo. 4 spac...
|
NULL
|
-3978531611220508841
|
NULL
|
click
|
ocr
|
NULL
|
PnostormroledeyFV faVsco.js#12077 on JY-20903-upda PnostormroledeyFV faVsco.js#12077 on JY-20903-update_activity-stageyUserinvitationdro.onp) CheckAndRetryRemoteMatch.php= custom.logscratch. &.ison=laravel.logA SF [jiminny@localhost]& HS_local [jiminny@localhost]console [PRODI© SyncPlanhat.phpO syncuserrllot.onp© ValidateSendingMessage.pCo kematchactviyoncrmoojectbetach.ong© ActivitiesMatchCrmCommand.php X ©MatchActivityCrmData.php© ImportParticipants.phpA console (EU]tiò accounts [EU]ii stages (EU]tid teams [EU]ImporbotkecoraingJoo.org© Activity.php x© FixActivitiesOpportunity.php© Opportunity.phpclass Acclvicleshacchurmcommana excenas commana[AAVValladtesenaingnotricatio> D WebhookE.gitkeep© ChangeLogContextCorrelatiov @ Mailv @ Activitiesc) exportLink.php© MailBoxFailedToConnect.p) smskeceivea.php© SmsRelavFailed.phpc)Trackkestored.onoCalendars>D crmReports(c) Mailable.ohoModelsM ActivityAskAnvthindm ConnectionM Contracts,M Crm(c) BusinessProcess.pnp© Configuration.php© ContactRole.php© Field.php© FieldData.phpc rielavalue.onpc Layout.onpc) Lavoutcnulv.onoc) Loq.phpC) Profile.phpC) RecordTvpe.phpc) SvncBatch.php> C7 ElasticSearch→→ FeatureM Opportunitv> M Particioant7 Plavbackithem:M Plavlist)N ScorecardMWebhook109111(C) Activitv nhn.oubulc tunccion nanaled.Sactivityids = sactivity->qetidou^} else {Steam = Team::+indcsteamd)*if (Steam === nulb) 1Sthis->error( strina: "Cannot find team."):2LOS,return CommandAzias: : FATLURE:Sthis->info( string: Steam->getName)'' | matching activities from ' • $from.' to' . $to);Sactivities = Activity::select( columns: 'activities.id')->join( table:-wnle ro collUitinconetezinieioperator:'=', $team->getIdo)'activities.created_at', [$from, $tol):1=' second: "usenc.id')if (SmatchFrom0therCrm) {itawtloweWalonoueeiluieeln: 'activities.crm_configuration_id', operator: '!=', Steam->getCrmConfi, 2118SactivityIds = Sactivities->pluck( column: 'id'):Sthis->info( string: 'Found activities: ' . SactivityIds->countO):if ( Sthis->confirm( question: "Do vou want to continue?') 'cneo2126foreach (SactivitvIds as $activitvld) {Sthis->disoatchonew Matchactivitvermbatalaint)Sactivitvid.fromConfiguration: SmatchFrom0therCrm ? $team->getCrmConfiguration : null,|[CREDIT_CARD]|2137213821392140return CommandALias::SUCCESS;21422144A console [STAGING]class Activity extends Model implements44 4169 M4 M102 .4 ^VOUDLICtunction updateActivityCrmData(array Srecords): void(C) A Promnt nhr21442147if (Sthis-›stage_id === null && $stage) 1$this-›stage_id = $stage->id;Sthic-scaved}elseif (Sstrategy== Updaceurmuarabyscracegy::concact)// Also update the parent activity if required, checking we don't create a mixed lead/account record.Sch1s->lead 10 = null:if (Sthis-›stage && $this->stage->getType• === Stage::TYPE LEAD) {Sch1s->stage 10 = null:II Don't trust previous matched account id as it might have been changed in the CRMif (Saccount && Saccount->id !== Sthis->account id) {Sthis->account_ 1d = Saccount->1d:if (Sopportunity && $this->opportunity_id !== $opportunity->id) {Sthis->onnortunitv id = Sonnortunitv->id:// Reset stage_id when opportunity changes to avoid stale stage from previous opportunity matchSthis->stade id = Sstaged->id.if (Sthis->stage_id === null && $stage) 1Sthic-sctaae id = Sctane-sid.if (Sopportunity && $this->value !== Sopportunity->value) {Cthic-svalme = Sooportunzcy»>value// Always set contact id when available, regardless of account id statusif (Sthis->contact_id === null && Scontact) {Sthis->contact_id = Scontact->idSthis->saveo:} elseif (Sstrategy == UpdateCrmDataByStrategv::Account &s $this->account_id === null) {I/ Also undate the narent activity if required, checking we don't create a mixed lead/account recordiSthis->lead 1d = null.if (Sthis->stage && Sthis->stage->getTvne() === Stage::TYPE LEAD) {Sthis->stage id = null:• Inu 14 May 10.04.14AskJiminnyReportActivityServiceTest vcascadePipedrive SDK EvaluaActivity Stage DiscrerImport CRM Activity T+0 ..Flow 1: Calendar Import - Participant ProcessingLocation: ImportParticipants::processuine S/ When: During calendar event impon wnen participants change or it'sahew acuvily triggerParticinant chandes detected durina imoort.• New activity being created from calendar Path: processParticipants() → updateActivityCrmData()Flow 2: Calencar moor - Wraoper MernodLocation: TmnortParticinants::undateActivitvCrmData() (line 121) When: After CRM lookun comnletes. beforelogging the update Trigger: Called from Flow 1's process() method Path: Wraps the Activity model's method withloggingFlow 3: Conference CRM RefreshLocation: ImportParticipants::refreshCrmData() (line 192) When: After a meeting finishes, when validatingparticipants and running CRM matching Trigger: ConferenceCrmMatcherJob dispatches this to refresh CRM data Path:ConferenceCrmMatcherJob → refreshCrmData( → particinantCrmLookun) → undateActivitvCrmbata(0)Clow 1. CPM Activity Service UindateLocation: CrmActivitvService::updateCrmData line 89 When: When explicitly updatina CRM data for an activity andits narticinants Triaaer. Manual CRM data undates or sunc onerations Path: undateParticinantsCrmlata() → undateActlSlow 5: Event Listener - Maich CRM ObiectLocation• MatchGrm0biect.«handlel) (line 112) When. When a coftnhone connestion onens or a narticinant inine• Connections Onened - dispatched when softohone connection obens (SoftPhoneManader lines 637, 672Dartscinantel loinod - disnatched whon narticinant inine conforenco (Twilia conferance evente) Dath- Gvent aMatchCrmObiect listener → CRM lookup → undateActivitvCrmData))Slow 6. Event Listener - Undate CRM DatalLocation: UpdateCrmData: : handle() (line 74) When: When a conference starts Triggered by event:conforoncoel Ctartodi - dienatched when conforando ctarte (Coccione| Startad lina 26 Twilin evente) DatheConferenceStarted event → UpdateCrmData listener → updateParticipantsCrmData() → updateActivityCrmDatafal .So all are only up to the poitn activity actual_end_data. Or is there something also later. Reveiw again and explain flowaThoucht for 1s >keас crmacuivilyservice.onpThought for 1s>Searched CrmActivityService,*updateCrmData in apoRead MatchActivitvCrmData.ohvThought for 1s ›Searched MatchActivityCrmData in appAM GMT+3.led weekly usage guota is exhausted. Purchase extra usage to continue using premium models. Quota resets May 17, 11:00Ask anvthina (84-L1« CodeSWE-16WN Windsurf Teams 2126-14UITF.RPo. 4 spac...
|
43481
|
NULL
|
NULL
|
NULL
|
|
43484
|
1587
|
12
|
2026-05-14T12:54:19.237894+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763259237_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43483
|
1587
|
11
|
2026-05-14T12:54:17.585744+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778763257585_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditEDViewGoHistoryWindowHelpQDescribe wh SlackFileEditEDViewGoHistoryWindowHelpQDescribe what you are looking for‹ 40lahl100% С8•Thu 14 May 15:54:17HomeDMsActivityLater..•MoreJiminny ...UnreadsThreadsHuddles• Drafts & sentDirectories01abExternal connections* Starred8jiminny-x-integrati...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office#support• Unread mentionsThreadsтогава не знам дали има нещо предиLukas Kovalik Just nowи като цяло при Join на конференцияLukas Kovalik Just nowможе и да не e calendarVasil Vasilev Just nowцялата тая чудесия трябва да я преразгледаме, и да я вкараме на едно място, с чисти правилаVasil Vasilev Just nowно за сега явно е окейVasil Vasilev Just nowдавам approveмисля да махна промяна от |Also send as direct message+AaYou're up to date• Vasil VasilevVasil Vasilev and youLukas Kovalik 22 minutes agoединствено CrmActivityService може да го тригьрне и при мануална команда за ремачване или при detach на обектVasil Vasilev 17 minutes agoпри рьчна промяна иил rетатсh сякаш също е окей да се викаReply...Also send as direct message+Аa...
|
NULL
|
4377706613728659233
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditEDViewGoHistoryWindowHelpQDescribe wh SlackFileEditEDViewGoHistoryWindowHelpQDescribe what you are looking for‹ 40lahl100% С8•Thu 14 May 15:54:17HomeDMsActivityLater..•MoreJiminny ...UnreadsThreadsHuddles• Drafts & sentDirectories01abExternal connections* Starred8jiminny-x-integrati...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# curiosity_lab# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office#support• Unread mentionsThreadsтогава не знам дали има нещо предиLukas Kovalik Just nowи като цяло при Join на конференцияLukas Kovalik Just nowможе и да не e calendarVasil Vasilev Just nowцялата тая чудесия трябва да я преразгледаме, и да я вкараме на едно място, с чисти правилаVasil Vasilev Just nowно за сега явно е окейVasil Vasilev Just nowдавам approveмисля да махна промяна от |Also send as direct message+AaYou're up to date• Vasil VasilevVasil Vasilev and youLukas Kovalik 22 minutes agoединствено CrmActivityService може да го тригьрне и при мануална команда за ремачване или при detach на обектVasil Vasilev 17 minutes agoпри рьчна промяна иил rетатсh сякаш също е окей да се викаReply...Also send as direct message+Аa...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43405
|
1583
|
66
|
2026-05-14T12:47:01.348905+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762821348_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
43404
|
NULL
|
NULL
|
NULL
|
|
43404
|
1583
|
65
|
2026-05-14T12:46:51.902354+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762811902_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-6767666495330057814
|
-8744677528123495868
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43403
|
1584
|
42
|
2026-05-14T12:46:40.540240+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762800540_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.38397607,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.12051077,"width":0.33178192,"height":0.87948924},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
43400
|
NULL
|
NULL
|
NULL
|
|
43402
|
1583
|
64
|
2026-05-14T12:46:40.512886+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762800512_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
43401
|
NULL
|
NULL
|
NULL
|
|
43401
|
1583
|
63
|
2026-05-14T12:46:37.429008+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762797429_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8043719072324535154
|
-8628527368849355612
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
SlackFileEditViewGoHistor Project: faVsco.js, menu
SlackFileEditViewGoHistoryWindowHomeDMSActivityFilesLaterMore+Jiminny ...# + More unreads# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesB. Vasil Vasilev®. Galya DimitrovaR. Aneliya AngelovaStefka Stoyanova: Todor StamatovMario Georgiev. Nikolay Ivanovdo James Graham2. Stoyan Tanev&. Steliyan Georgiev&. Petko KashinskiLukas Kovalik y...l:: AppsToastJira CloudHelplhlDescribe what you are looking forVasil VasilevMessagesAdd canvas@ Files& Pins +Lukas Kovalik 3:31 PMToday ~единствено CrmActivityService може да го тригьрне и при мануална команда за ремачване или при detach на обект1 reply Today at 3:35 PMLukas Kovalik 3:34 PMи се вика не само при подмяна на opportunity но и при update на проспектVasil Vasilev 3:36 PMupdate на проспект в какъв смисьл?Lukas Kovalik 3:36 PM[Slead, Saccount, Sopportunity, Scontact, Sstage] = Srecords;което се мачнеVasil Vasilev 3:38 PMно това пак е при ново мачване на срм обектии е по скоро изключениенали така ?Lukas Kovalik 3:40 PMне знам дали само нова, когато има trigger (предимно преди или до края на среща) тогава се мачваможе и да е стар обект, вече мачнатLukas Kovalik 3:41 PMно да трябва да има opportunity (и промяна по него) да стигне до моята промяна5 replies Last reply today at 3:45 PMVasil Vasilev 3:41 PMпри стар обект нещо ще накара тоя обект да бъде ремачнат100% C8•Thu 14 May 15:46:376 0Message Vasil Vasilev+...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43394
|
1583
|
59
|
2026-05-14T12:46:30.098996+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762790098_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43392
|
1584
|
38
|
2026-05-14T12:46:28.510007+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762788510_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"4","depth":4,"bounds":{"left":0.38397607,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Jobs\\Crm\\MatchActivityCrmData;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Team;\nuse Symfony\\Component\\Console\\Command\\Command as CommandAlias;\n\nclass ActivitiesMatchCrmCommand extends Command\n{\n protected $signature = 'activity:match-crm\n {--teamId=}\n {--from=}\n {--to=}\n {--activityId=}\n {--matchFromOtherCrm}\n {--remoteSearch}\n {--sync}\n ';\n\n public function handle(): int\n {\n $teamId = $this->option('teamId');\n $from = $this->option('from');\n $to = $this->option('to');\n $matchFromOtherCrm = $this->option('matchFromOtherCrm');\n $remoteSearch = $this->option('remoteSearch');\n $activityId = $this->option('activityId');\n\n $validator = Validator::make(\n [\n 'teamId' => $teamId,\n 'from' => $from,\n 'to' => $to,\n 'matchFromOtherCrm' => $matchFromOtherCrm,\n 'activityId' => $activityId,\n 'remoteSearch' => $remoteSearch,\n ],\n [\n 'teamId' => ['required_without:activityId', 'numeric', 'nullable'],\n 'from' => ['required_without:activityId', 'date', 'nullable'],\n 'to' => ['required_without:activityId', 'date', 'nullable'],\n 'matchFromOtherCrm' => ['required', 'boolean'],\n 'remoteSearch' => ['required', 'boolean'],\n 'activityId' => ['numeric', 'nullable'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return CommandAlias::FAILURE;\n }\n\n if ($activityId) {\n $activity = Activity::find((int) $activityId);\n if ($activity === null) {\n $this->error('Cannot find activity.');\n\n return CommandAlias::FAILURE;\n }\n $team = $activity->getTeam();\n $this->info($activity->getTitle() . ' found.');\n\n $activityIds = [$activity->getId()];\n } else {\n $team = Team::find($teamId);\n if ($team === null) {\n $this->error('Cannot find team.');\n\n return CommandAlias::FAILURE;\n }\n\n $this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);\n\n $activities = Activity::select('activities.id')\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->where('users.team_id', '=', $team->getId())\n ->whereBetween('activities.created_at', [$from, $to]);\n if ($matchFromOtherCrm) {\n $activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());\n }\n\n $activityIds = $activities->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n }\n\n if (! $this->confirm('Do you want to continue?')) {\n die();\n }\n\n foreach ($activityIds as $activityId) {\n $this->dispatch(\n new MatchActivityCrmData(\n activityId: (int) $activityId,\n fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,\n remoteSearch: $remoteSearch,\n )\n );\n }\n\n return CommandAlias::SUCCESS;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.12051077,"width":0.33178192,"height":0.87948924},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8301692114999181661
|
478691191938595332
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
4
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Jobs\Crm\MatchActivityCrmData;
use Jiminny\Models\Activity;
use Jiminny\Models\Team;
use Symfony\Component\Console\Command\Command as CommandAlias;
class ActivitiesMatchCrmCommand extends Command
{
protected $signature = 'activity:match-crm
{--teamId=}
{--from=}
{--to=}
{--activityId=}
{--matchFromOtherCrm}
{--remoteSearch}
{--sync}
';
public function handle(): int
{
$teamId = $this->option('teamId');
$from = $this->option('from');
$to = $this->option('to');
$matchFromOtherCrm = $this->option('matchFromOtherCrm');
$remoteSearch = $this->option('remoteSearch');
$activityId = $this->option('activityId');
$validator = Validator::make(
[
'teamId' => $teamId,
'from' => $from,
'to' => $to,
'matchFromOtherCrm' => $matchFromOtherCrm,
'activityId' => $activityId,
'remoteSearch' => $remoteSearch,
],
[
'teamId' => ['required_without:activityId', 'numeric', 'nullable'],
'from' => ['required_without:activityId', 'date', 'nullable'],
'to' => ['required_without:activityId', 'date', 'nullable'],
'matchFromOtherCrm' => ['required', 'boolean'],
'remoteSearch' => ['required', 'boolean'],
'activityId' => ['numeric', 'nullable'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return CommandAlias::FAILURE;
}
if ($activityId) {
$activity = Activity::find((int) $activityId);
if ($activity === null) {
$this->error('Cannot find activity.');
return CommandAlias::FAILURE;
}
$team = $activity->getTeam();
$this->info($activity->getTitle() . ' found.');
$activityIds = [$activity->getId()];
} else {
$team = Team::find($teamId);
if ($team === null) {
$this->error('Cannot find team.');
return CommandAlias::FAILURE;
}
$this->info($team->getName() . ' | matching activities from ' . $from . ' to ' . $to);
$activities = Activity::select('activities.id')
->join('users', 'activities.user_id', '=', 'users.id')
->where('users.team_id', '=', $team->getId())
->whereBetween('activities.created_at', [$from, $to]);
if ($matchFromOtherCrm) {
$activities->where('activities.crm_configuration_id', '!=', $team->getCrmConfigurationId());
}
$activityIds = $activities->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
}
if (! $this->confirm('Do you want to continue?')) {
die();
}
foreach ($activityIds as $activityId) {
$this->dispatch(
new MatchActivityCrmData(
activityId: (int) $activityId,
fromConfiguration: $matchFromOtherCrm ? $team->getCrmConfiguration() : null,
remoteSearch: $remoteSearch,
)
);
}
return CommandAlias::SUCCESS;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
43391
|
NULL
|
NULL
|
NULL
|
|
43240
|
1580
|
34
|
2026-05-14T12:35:52.372093+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762152372_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
1
5
Previous Highlighted Error
Next Highlighted Error...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.37466756,"top":0.12529927,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"5","depth":4,"bounds":{"left":0.38397607,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-1133241668058416712
|
-8708554121841366074
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
1
5
Previous Highlighted Error
Next Highlighted Error
PhostormVIewINavicarecodeLaravelKeractorWindowFV faVsco.js( #12077 on JY-20903-update_activity-stage-on...harProjecty© UserinvitationDTO.php) CheckAndRetryRemoteMatch.php> @ WebhookCo kematchactviyoncrmoojectbetach.ongC) MatchActivityermData.pnp© ImportParticipants.phpg Account.onp© UpdateCrmData.php(©) MatchCrmObject.pngg Acuvity.ono:?php©) Adaress.ongC) AIPrompt.onpc) Aulomaleckeport.ono© AutomatedReportResult.phpc) calendar.pholamespace Jiminny Services crm.c) callimport.phpc) coachinaFeedback.ohpIse...© CoachinaFeedbackVisibilitv.pc) CoachinaSection.phpilass CrmActivityServicec) coachinoSectioncriterion.onc(c) CoachinoSectioncriterionFeepublic function -_construct(© CoachinaSectionFeedback.ohprivate readonly TeamRepository$teamRepository,C. CommentAbstract. ohoprivate readonly CachedCrmServiceDecoratorSdecorator.© Commentinterface.phpprivate readonly EmailHelperSemailHelper,© Contact.php(c) Device nhnprivate readonly ResolveTeamCrmConnectionprivate readonly LoggerInterfaceSteamCrmResolver,$logger,© EmailMessage.php© GenericAiPrompt.php© Group.php© Inbox.php© InboxEmail.php) 1.J/*x* Updates CRM data for an activity and its participants.© InboxEmailBatch.php* NOTE: This method performs multiple database writes and should be called© Invitation.php* wiunin a crunsaccion ou une caller to ensure aromicitu.e Joblog.ono© JobTitle.php* doaram ActIvity sactivituc Lancuace.ono* Ananam bool SremoteSearchc) LanquageDialect.phoc) Lead.php© MobileSetting.php* drhrows contalnerExceptzoninterrace* dchrows notroundzxcentzonunterrace* dchrows ExcentzonC Model.phpc) Moment.phpc) Nudge,ono© NudaeRun.ohnpublic function updateCrmDatadC) @pportunitv.ohdActivity Sactivitv.(C) Partner. ohobool SremoteSearch = false.): void (SermService = nuhC) Permission.oho(c) PhoneNumber.nhoSparticipants = $activity->getParticipants:(c) Plavbackitheme.ohnSteam = Sactivitv->aetTeamo•(C) Plavbook nhnl(C) PlavbookCateaorv .nhnlSnrosnec+SearchStrateav = Prosnec+SearchStnateavFactonv.match(Steam)l(C) Plavlist nhnlif (SprospectSearchStrategy->ignoreCrmMatchDataO) {(C) Patel imit nhn(C) Reaion.nhnle Polo nhnSthis->logger->info('[CrmActivityService) Ignoring crm data because of prospect strategy', ['activity_id' => $activity->getId)'strategy' => get class($prospectSearchStrategy)© RoleChangeEvent.php© ScopeGroup.php© Session.phpnortihn"Checked out IV.20902-undate activitv-ctade-on-onnortunitv-chande (25 minutes aao))= custom.logscratch. &.ison= laravel.logA SF jiminny@localhost]& HS_local [jiminny@localhost]& console [PROD]A console (EU]tiò accounts [EU]ii stages (EU]tid teams [EU]© ImportBotRecordingJob.php© Activity.php X© FixActivitiesOpportunity.php x© Opportunity.php& console SlAGiNGclass Actoppor conzeg muotodet ampcementsContact|null,84 B169 M4 M 102 24 ^ scage nullstring|null*} Srecords* apanam Participant $participant participant the CRM data is associated withpublic function updateParticipantCrmData(array Srecords. Participant Sparticipant): void{...}* Uodates activitu Cri data.* oparam arrausAccountnuluOoportunitulnulzContact/nulzStage|null,strinalnulz*- Srecordspublic function updateActivityCrmData(array Srecords): void// Extract the records.[Slead, Saccount, Sopportunity, $contact, $stage] = Srecords;Sresolver = Sthis->getUpdateCrmDataResolverO:Sstrategy = Sresolver->resolveForActivity(Slead, $contact, $account):if (Sstrategy == UpdateCrmDataByStrategy::Lead) {I/ Also update the parent activity if required, checking we don't create a mixed lead/account record.if (Sthis->account id === null && Sthis-›contact id === null && Sthis->lead id === nulb) {Sth1s->lead_1d = Slead->1d*if (Sthis->stage_ id === null && Sstage) {sthis->staqe_1d = Sstaqe->1d:Sthis->saveo:} elseif (Sstrateav == UodateCrmDataßvStrateav::Contact) {Also uodate the parent activityif required. checkina we don't create a mixed lead/account recordi14 (this-sstade se Sthis->stanp->aetTvneQ === Stade• • TVPS ISAm)<Non'+ +oust nnevious matched account id as i+ miaht have heen chanaed in the CRMkal100% L2• Thu 14 May 15:35:52AskJiminnyReportActivityServiceTest vcascadePipedrive SDK EvaluaActivity Stage DiscrerImport CRM Activity T+0 ..Location: CrmActivitvServilce::uodateCrmData (line 89•Manual command execution: Activ1t1esMatchcrmcommand - manually triggered by admin developer•CRM entity deletion: When a lead/contact/account/opportunity is deleted from CRM via DeleteCrmEntitvTrait• Remote retry: CheckAndRetryRemoteMatch job when local search failsFlow breakdown:1. Trigger points.•ActivitiesMatchCrmCommand - artisan command to bulk match CRM data for activities• DetachActivity0bject event - dispatched when CRM entities are deleted from the system•CheckAndRetryRemoteMatch - dispatched when local CRM search tails and remote search is needec2. Process• MatchAct ivitvormbata iob is dispatched with activitvD• Job resets all CRM mappings on activity and participants (sets to null)Optionally switches CRM contiguration it fronConfiquration is providedCalls GrmictivitvService..undatefrmlatal)Service iterates through participants, pertorms CRM lookups (emall → phone → name → domain)Undates narticinant CPM data firctSelects best match from all participantsCalls Activitv:undateActivitvCrmlatalo with bect match3. Key difference from other flows:• Resets all CRM mappings first (lines 161-167 in MatchActivityCrmData)• can switch CRM contiguration (lines 193-213)Supports remote search (calls CRM APl if SremoteSearch = true )•Runs in a database transaction tor atomicityCan be triadered manualiv bv admin commandoA Use cases• Fixing incorrect CRM matches after the fact•Re-matchina when CRM contiquration changes• Re-matching when CRM entities are deleted•3ulk tixina activities tor a date ranqeRetrvina failed remote CPM lookuncGal .ok aive me more details on each triager in flow 4Flow 4 Triader Detailsd weekly usage quota is exhausted. Purchase extra usage to continue using premium models. Quota resets May 17, 11:00Ask anvthina (84L)« Code SWF-1.6•0 1.W Windsurf Toams 2146-16/24 charc)UTE.8io 4 spaces...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
43239
|
1579
|
27
|
2026-05-14T12:35:52.404096+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778762152404_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
1
5
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm;
use Illuminate\Support\Collection;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Models\Account;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Lead;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Participant;
use Jiminny\Models\Stage;
use Jiminny\Models\Team;
use Jiminny\Models\User;
use Jiminny\Services\ResolveTeamCrmConnection;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use Exception;
use Throwable;
class CrmActivityService
{
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly CachedCrmServiceDecorator $decorator,
private readonly EmailHelper $emailHelper,
private readonly ResolveTeamCrmConnection $teamCrmResolver,
private readonly LoggerInterface $logger,
) {
}
/**
* Updates CRM data for an activity and its participants.
*
* NOTE: This method performs multiple database writes and should be called
* within a transaction by the caller to ensure atomicity.
*
* @param Activity $activity
* @param bool $remoteSearch
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function updateCrmData(
Activity $activity,
bool $remoteSearch = false,
): void {
$crmService = null;
$participants = $activity->getParticipants();
$team = $activity->getTeam();
$prospectSearchStrategy = ProspectSearchStrategyFactory::match($team);
if ($prospectSearchStrategy->ignoreCrmMatchData()) {
$this->logger->info('[CrmActivityService] Ignoring crm data because of prospect strategy', [
'activity_id' => $activity->getId(),
'strategy' => get_class($prospectSearchStrategy),
]);
return;
}
if ($remoteSearch) {
try {
$crmService = $this->teamCrmResolver->resolveForTeam($team);
} catch (SocialAccountTokenInvalidException) {
$this->logger->warning('[CrmActivityService] CRM token expired, falling back to local search', [
'activity_id' => $activity->getId(),
'team_id' => $team->getId(),
]);
}
}
$records = $this->updateParticipantsCrmData(
team: $team,
activity: $activity,
participants: $participants,
crmService: $crmService,
);
if (! empty($records)) {
$activity->updateActivityCrmData($records);
}
$activity->refresh();
}
/**
* @param Collection<Participant> $participants
*
* @throws Exception
*
* @return array{
* Lead|null,
* Account|null,
* Opportunity|null,
* Contact|null,
* Stage|null,
* string|null
*}|array{}
*/
private function updateParticipantsCrmData(
Team $team,
Activity $activity,
Collection $participants,
?ServiceInterface $crmService = null,
): array {
$matchedRecords = [];
$matchedDomainRecords = [];
$this->validateCrmConfiguration($activity);
$this->decorator->setConfiguration($activity->getCrm());
$this->decorator->setCrmService($crmService);
foreach ($participants as $participant) {
if ($this->shouldSkipParticipant($participant)) {
continue;
}
if (! $this->shouldPerformLookup($participant, $team)) {
$this->logger->info('[CrmActivityService] Email domain belongs to the team, skipping crm lookup', [
'activity_id' => $activity->getId(),
'team_id' => $team->getId(),
'email' => $participant->getEmailAddress(),
]);
$this->attachUserIfExists($participant, $team);
continue;
}
$records = $this->findCrmRecords($participant, $activity);
if (! empty($records)) {
$matchedRecords[] = $records;
} else {
$records = $this->findCrmDomainRecords(
crmService: $crmService,
participant: $participant,
activity: $activity,
);
if (! empty($records)) {
$matchedDomainRecords[] = $records;
}
}
if (empty($records)) {
continue;
}
try {
$activity->updateParticipantCrmData($records, $participant);
} catch (Throwable $ex) {
$this->logger->error('[CrmActivityService] Failed to update participant CRM data', [
'activity_id' => $activity->getId(),
'participant_id' => $participant->getId(),
'exception' => $ex->getMessage(),
]);
continue;
}
}
$bestMatch = $this->getBestMatch(
matchedRecords : $matchedRecords,
matchedDomainRecords: $matchedDomainRecords,
);
$this->logger->info('[CrmActivityService] CRM matching completed', [
'activity_id' => $activity->getId(),
'participants_processed' => $participants->count(),
'exact_matches' => count($matchedRecords),
'domain_matches' => count($matchedDomainRecords),
'best_match_found' => ! empty($bestMatch),
]);
return $bestMatch;
}
private function shouldPerformLookup(Participant $participant, Team $team): bool
{
if ($participant->hasEmailAddress()) {
return $this->emailHelper->shouldPerformLookup($team, $participant->getEmailAddress());
}
return true;
}
private function validateCrmConfiguration(Activity $activity): void
{
if ($activity->getCrm() === null) {
throw new InvalidArgumentException('Cannot find CRM configuration');
}
}
private function getBestMatch(?array $matchedRecords, ?array $matchedDomainRecords): array
{
return RecordSelector::pickBestFromLists($matchedRecords, $matchedDomainRecords);
}
private function findCrmRecords(Participant $participant, Activity $activity): ?array
{
$records = null;
if ($participant->hasEmailAddress()) {
$records = $this->decorator->matchExactlyByEmail(
email: $participant->getEmailAddress(),
userId: $activity->getUser()->getId()
);
}
if (empty($records) && $participant->getPhoneNumber() !== null) {
$records = $this->decorator->matchByPhone(
phone: $participant->getPhoneNumber(),
userId: $activity->getUser()->getId(),
);
}
if (empty($records) && $participant->getName() !== null) {
$records = $this->decorator->matchByName(
name: $participant->getName(),
userId: $activity->getUser()->getId(),
);
}
return $records;
}
private function shouldSkipParticipant(Participant $participant): bool
{
return $participant->hasUser();
}
private function attachUserIfExists(Participant $participant, Team $team): void
{
if ($participant->hasEmailAddress() === false) {
return;
}
$user = $this->teamRepository->findActiveTeamMemberByEmail($team, $participant->getEmailAddress());
if ($user instanceof User) {
$participant->user_id = $user->getId();
$participant->save();
}
}
private function findCrmDomainRecords(
?ServiceInterface $crmService,
Participant $participant,
Activity $activity,
): array {
if ($participant->hasEmailAddress()) {
$this->decorator->setConfiguration($activity->getCrm());
$this->decorator->setCrmService($crmService);
$records = $this->decorator->matchByDomain(
email: $participant->getEmailAddress(),
userId: $activity->getUser()->getId()
);
if (! empty($records)) {
return $records;
}
}
return [];
}
}
Sync Changes
Hide This Notification
Code changed:
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"5","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Crm;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\SocialAccountTokenInvalidException;\nuse Jiminny\\Models\\Account;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Lead;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Participant;\nuse Jiminny\\Models\\Stage;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse Psr\\Container\\ContainerExceptionInterface;\nuse Psr\\Container\\NotFoundExceptionInterface;\nuse Psr\\Log\\LoggerInterface;\nuse Exception;\nuse Throwable;\n\nclass CrmActivityService\n{\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly CachedCrmServiceDecorator $decorator,\n private readonly EmailHelper $emailHelper,\n private readonly ResolveTeamCrmConnection $teamCrmResolver,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n /**\n * Updates CRM data for an activity and its participants.\n *\n * NOTE: This method performs multiple database writes and should be called\n * within a transaction by the caller to ensure atomicity.\n *\n * @param Activity $activity\n * @param bool $remoteSearch\n *\n * @throws ContainerExceptionInterface\n * @throws NotFoundExceptionInterface\n * @throws Exception\n */\n public function updateCrmData(\n Activity $activity,\n bool $remoteSearch = false,\n ): void {\n $crmService = null;\n $participants = $activity->getParticipants();\n $team = $activity->getTeam();\n\n $prospectSearchStrategy = ProspectSearchStrategyFactory::match($team);\n if ($prospectSearchStrategy->ignoreCrmMatchData()) {\n $this->logger->info('[CrmActivityService] Ignoring crm data because of prospect strategy', [\n 'activity_id' => $activity->getId(),\n 'strategy' => get_class($prospectSearchStrategy),\n ]);\n\n return;\n }\n\n if ($remoteSearch) {\n try {\n $crmService = $this->teamCrmResolver->resolveForTeam($team);\n } catch (SocialAccountTokenInvalidException) {\n $this->logger->warning('[CrmActivityService] CRM token expired, falling back to local search', [\n 'activity_id' => $activity->getId(),\n 'team_id' => $team->getId(),\n ]);\n }\n }\n\n $records = $this->updateParticipantsCrmData(\n team: $team,\n activity: $activity,\n participants: $participants,\n crmService: $crmService,\n );\n\n if (! empty($records)) {\n $activity->updateActivityCrmData($records);\n }\n\n $activity->refresh();\n }\n\n /**\n * @param Collection<Participant> $participants\n *\n * @throws Exception\n *\n * @return array{\n * Lead|null,\n * Account|null,\n * Opportunity|null,\n * Contact|null,\n * Stage|null,\n * string|null\n *}|array{}\n */\n private function updateParticipantsCrmData(\n Team $team,\n Activity $activity,\n Collection $participants,\n ?ServiceInterface $crmService = null,\n ): array {\n $matchedRecords = [];\n $matchedDomainRecords = [];\n\n $this->validateCrmConfiguration($activity);\n $this->decorator->setConfiguration($activity->getCrm());\n $this->decorator->setCrmService($crmService);\n\n foreach ($participants as $participant) {\n if ($this->shouldSkipParticipant($participant)) {\n continue;\n }\n\n if (! $this->shouldPerformLookup($participant, $team)) {\n $this->logger->info('[CrmActivityService] Email domain belongs to the team, skipping crm lookup', [\n 'activity_id' => $activity->getId(),\n 'team_id' => $team->getId(),\n 'email' => $participant->getEmailAddress(),\n ]);\n\n $this->attachUserIfExists($participant, $team);\n\n continue;\n }\n\n $records = $this->findCrmRecords($participant, $activity);\n\n if (! empty($records)) {\n $matchedRecords[] = $records;\n } else {\n $records = $this->findCrmDomainRecords(\n crmService: $crmService,\n participant: $participant,\n activity: $activity,\n );\n if (! empty($records)) {\n $matchedDomainRecords[] = $records;\n }\n }\n\n if (empty($records)) {\n continue;\n }\n\n try {\n $activity->updateParticipantCrmData($records, $participant);\n } catch (Throwable $ex) {\n $this->logger->error('[CrmActivityService] Failed to update participant CRM data', [\n 'activity_id' => $activity->getId(),\n 'participant_id' => $participant->getId(),\n 'exception' => $ex->getMessage(),\n ]);\n\n continue;\n }\n }\n\n $bestMatch = $this->getBestMatch(\n matchedRecords : $matchedRecords,\n matchedDomainRecords: $matchedDomainRecords,\n );\n\n $this->logger->info('[CrmActivityService] CRM matching completed', [\n 'activity_id' => $activity->getId(),\n 'participants_processed' => $participants->count(),\n 'exact_matches' => count($matchedRecords),\n 'domain_matches' => count($matchedDomainRecords),\n 'best_match_found' => ! empty($bestMatch),\n ]);\n\n return $bestMatch;\n }\n\n private function shouldPerformLookup(Participant $participant, Team $team): bool\n {\n if ($participant->hasEmailAddress()) {\n return $this->emailHelper->shouldPerformLookup($team, $participant->getEmailAddress());\n }\n\n return true;\n }\n\n private function validateCrmConfiguration(Activity $activity): void\n {\n if ($activity->getCrm() === null) {\n throw new InvalidArgumentException('Cannot find CRM configuration');\n }\n }\n\n private function getBestMatch(?array $matchedRecords, ?array $matchedDomainRecords): array\n {\n return RecordSelector::pickBestFromLists($matchedRecords, $matchedDomainRecords);\n }\n\n private function findCrmRecords(Participant $participant, Activity $activity): ?array\n {\n $records = null;\n\n if ($participant->hasEmailAddress()) {\n $records = $this->decorator->matchExactlyByEmail(\n email: $participant->getEmailAddress(),\n userId: $activity->getUser()->getId()\n );\n }\n\n if (empty($records) && $participant->getPhoneNumber() !== null) {\n $records = $this->decorator->matchByPhone(\n phone: $participant->getPhoneNumber(),\n userId: $activity->getUser()->getId(),\n );\n }\n\n if (empty($records) && $participant->getName() !== null) {\n $records = $this->decorator->matchByName(\n name: $participant->getName(),\n userId: $activity->getUser()->getId(),\n );\n }\n\n return $records;\n }\n\n private function shouldSkipParticipant(Participant $participant): bool\n {\n return $participant->hasUser();\n }\n\n private function attachUserIfExists(Participant $participant, Team $team): void\n {\n if ($participant->hasEmailAddress() === false) {\n return;\n }\n\n $user = $this->teamRepository->findActiveTeamMemberByEmail($team, $participant->getEmailAddress());\n\n if ($user instanceof User) {\n $participant->user_id = $user->getId();\n $participant->save();\n }\n }\n\n private function findCrmDomainRecords(\n ?ServiceInterface $crmService,\n Participant $participant,\n Activity $activity,\n ): array {\n if ($participant->hasEmailAddress()) {\n $this->decorator->setConfiguration($activity->getCrm());\n $this->decorator->setCrmService($crmService);\n\n $records = $this->decorator->matchByDomain(\n email: $participant->getEmailAddress(),\n userId: $activity->getUser()->getId()\n );\n if (! empty($records)) {\n return $records;\n }\n }\n\n return [];\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Crm;\n\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\SocialAccountTokenInvalidException;\nuse Jiminny\\Models\\Account;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Lead;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Participant;\nuse Jiminny\\Models\\Stage;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse Psr\\Container\\ContainerExceptionInterface;\nuse Psr\\Container\\NotFoundExceptionInterface;\nuse Psr\\Log\\LoggerInterface;\nuse Exception;\nuse Throwable;\n\nclass CrmActivityService\n{\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly CachedCrmServiceDecorator $decorator,\n private readonly EmailHelper $emailHelper,\n private readonly ResolveTeamCrmConnection $teamCrmResolver,\n private readonly LoggerInterface $logger,\n ) {\n }\n\n /**\n * Updates CRM data for an activity and its participants.\n *\n * NOTE: This method performs multiple database writes and should be called\n * within a transaction by the caller to ensure atomicity.\n *\n * @param Activity $activity\n * @param bool $remoteSearch\n *\n * @throws ContainerExceptionInterface\n * @throws NotFoundExceptionInterface\n * @throws Exception\n */\n public function updateCrmData(\n Activity $activity,\n bool $remoteSearch = false,\n ): void {\n $crmService = null;\n $participants = $activity->getParticipants();\n $team = $activity->getTeam();\n\n $prospectSearchStrategy = ProspectSearchStrategyFactory::match($team);\n if ($prospectSearchStrategy->ignoreCrmMatchData()) {\n $this->logger->info('[CrmActivityService] Ignoring crm data because of prospect strategy', [\n 'activity_id' => $activity->getId(),\n 'strategy' => get_class($prospectSearchStrategy),\n ]);\n\n return;\n }\n\n if ($remoteSearch) {\n try {\n $crmService = $this->teamCrmResolver->resolveForTeam($team);\n } catch (SocialAccountTokenInvalidException) {\n $this->logger->warning('[CrmActivityService] CRM token expired, falling back to local search', [\n 'activity_id' => $activity->getId(),\n 'team_id' => $team->getId(),\n ]);\n }\n }\n\n $records = $this->updateParticipantsCrmData(\n team: $team,\n activity: $activity,\n participants: $participants,\n crmService: $crmService,\n );\n\n if (! empty($records)) {\n $activity->updateActivityCrmData($records);\n }\n\n $activity->refresh();\n }\n\n /**\n * @param Collection<Participant> $participants\n *\n * @throws Exception\n *\n * @return array{\n * Lead|null,\n * Account|null,\n * Opportunity|null,\n * Contact|null,\n * Stage|null,\n * string|null\n *}|array{}\n */\n private function updateParticipantsCrmData(\n Team $team,\n Activity $activity,\n Collection $participants,\n ?ServiceInterface $crmService = null,\n ): array {\n $matchedRecords = [];\n $matchedDomainRecords = [];\n\n $this->validateCrmConfiguration($activity);\n $this->decorator->setConfiguration($activity->getCrm());\n $this->decorator->setCrmService($crmService);\n\n foreach ($participants as $participant) {\n if ($this->shouldSkipParticipant($participant)) {\n continue;\n }\n\n if (! $this->shouldPerformLookup($participant, $team)) {\n $this->logger->info('[CrmActivityService] Email domain belongs to the team, skipping crm lookup', [\n 'activity_id' => $activity->getId(),\n 'team_id' => $team->getId(),\n 'email' => $participant->getEmailAddress(),\n ]);\n\n $this->attachUserIfExists($participant, $team);\n\n continue;\n }\n\n $records = $this->findCrmRecords($participant, $activity);\n\n if (! empty($records)) {\n $matchedRecords[] = $records;\n } else {\n $records = $this->findCrmDomainRecords(\n crmService: $crmService,\n participant: $participant,\n activity: $activity,\n );\n if (! empty($records)) {\n $matchedDomainRecords[] = $records;\n }\n }\n\n if (empty($records)) {\n continue;\n }\n\n try {\n $activity->updateParticipantCrmData($records, $participant);\n } catch (Throwable $ex) {\n $this->logger->error('[CrmActivityService] Failed to update participant CRM data', [\n 'activity_id' => $activity->getId(),\n 'participant_id' => $participant->getId(),\n 'exception' => $ex->getMessage(),\n ]);\n\n continue;\n }\n }\n\n $bestMatch = $this->getBestMatch(\n matchedRecords : $matchedRecords,\n matchedDomainRecords: $matchedDomainRecords,\n );\n\n $this->logger->info('[CrmActivityService] CRM matching completed', [\n 'activity_id' => $activity->getId(),\n 'participants_processed' => $participants->count(),\n 'exact_matches' => count($matchedRecords),\n 'domain_matches' => count($matchedDomainRecords),\n 'best_match_found' => ! empty($bestMatch),\n ]);\n\n return $bestMatch;\n }\n\n private function shouldPerformLookup(Participant $participant, Team $team): bool\n {\n if ($participant->hasEmailAddress()) {\n return $this->emailHelper->shouldPerformLookup($team, $participant->getEmailAddress());\n }\n\n return true;\n }\n\n private function validateCrmConfiguration(Activity $activity): void\n {\n if ($activity->getCrm() === null) {\n throw new InvalidArgumentException('Cannot find CRM configuration');\n }\n }\n\n private function getBestMatch(?array $matchedRecords, ?array $matchedDomainRecords): array\n {\n return RecordSelector::pickBestFromLists($matchedRecords, $matchedDomainRecords);\n }\n\n private function findCrmRecords(Participant $participant, Activity $activity): ?array\n {\n $records = null;\n\n if ($participant->hasEmailAddress()) {\n $records = $this->decorator->matchExactlyByEmail(\n email: $participant->getEmailAddress(),\n userId: $activity->getUser()->getId()\n );\n }\n\n if (empty($records) && $participant->getPhoneNumber() !== null) {\n $records = $this->decorator->matchByPhone(\n phone: $participant->getPhoneNumber(),\n userId: $activity->getUser()->getId(),\n );\n }\n\n if (empty($records) && $participant->getName() !== null) {\n $records = $this->decorator->matchByName(\n name: $participant->getName(),\n userId: $activity->getUser()->getId(),\n );\n }\n\n return $records;\n }\n\n private function shouldSkipParticipant(Participant $participant): bool\n {\n return $participant->hasUser();\n }\n\n private function attachUserIfExists(Participant $participant, Team $team): void\n {\n if ($participant->hasEmailAddress() === false) {\n return;\n }\n\n $user = $this->teamRepository->findActiveTeamMemberByEmail($team, $participant->getEmailAddress());\n\n if ($user instanceof User) {\n $participant->user_id = $user->getId();\n $participant->save();\n }\n }\n\n private function findCrmDomainRecords(\n ?ServiceInterface $crmService,\n Participant $participant,\n Activity $activity,\n ): array {\n if ($participant->hasEmailAddress()) {\n $this->decorator->setConfiguration($activity->getCrm());\n $this->decorator->setCrmService($crmService);\n\n $records = $this->decorator->matchByDomain(\n email: $participant->getEmailAddress(),\n userId: $activity->getUser()->getId()\n );\n if (! empty($records)) {\n return $records;\n }\n }\n\n return [];\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8486787440857229820
|
-8382938072294999842
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Sync Changes
Hide This Notification
Code changed:
Hide
1
5
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Crm;
use Illuminate\Support\Collection;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\SocialAccountTokenInvalidException;
use Jiminny\Models\Account;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Lead;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Participant;
use Jiminny\Models\Stage;
use Jiminny\Models\Team;
use Jiminny\Models\User;
use Jiminny\Services\ResolveTeamCrmConnection;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use Exception;
use Throwable;
class CrmActivityService
{
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly CachedCrmServiceDecorator $decorator,
private readonly EmailHelper $emailHelper,
private readonly ResolveTeamCrmConnection $teamCrmResolver,
private readonly LoggerInterface $logger,
) {
}
/**
* Updates CRM data for an activity and its participants.
*
* NOTE: This method performs multiple database writes and should be called
* within a transaction by the caller to ensure atomicity.
*
* @param Activity $activity
* @param bool $remoteSearch
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function updateCrmData(
Activity $activity,
bool $remoteSearch = false,
): void {
$crmService = null;
$participants = $activity->getParticipants();
$team = $activity->getTeam();
$prospectSearchStrategy = ProspectSearchStrategyFactory::match($team);
if ($prospectSearchStrategy->ignoreCrmMatchData()) {
$this->logger->info('[CrmActivityService] Ignoring crm data because of prospect strategy', [
'activity_id' => $activity->getId(),
'strategy' => get_class($prospectSearchStrategy),
]);
return;
}
if ($remoteSearch) {
try {
$crmService = $this->teamCrmResolver->resolveForTeam($team);
} catch (SocialAccountTokenInvalidException) {
$this->logger->warning('[CrmActivityService] CRM token expired, falling back to local search', [
'activity_id' => $activity->getId(),
'team_id' => $team->getId(),
]);
}
}
$records = $this->updateParticipantsCrmData(
team: $team,
activity: $activity,
participants: $participants,
crmService: $crmService,
);
if (! empty($records)) {
$activity->updateActivityCrmData($records);
}
$activity->refresh();
}
/**
* @param Collection<Participant> $participants
*
* @throws Exception
*
* @return array{
* Lead|null,
* Account|null,
* Opportunity|null,
* Contact|null,
* Stage|null,
* string|null
*}|array{}
*/
private function updateParticipantsCrmData(
Team $team,
Activity $activity,
Collection $participants,
?ServiceInterface $crmService = null,
): array {
$matchedRecords = [];
$matchedDomainRecords = [];
$this->validateCrmConfiguration($activity);
$this->decorator->setConfiguration($activity->getCrm());
$this->decorator->setCrmService($crmService);
foreach ($participants as $participant) {
if ($this->shouldSkipParticipant($participant)) {
continue;
}
if (! $this->shouldPerformLookup($participant, $team)) {
$this->logger->info('[CrmActivityService] Email domain belongs to the team, skipping crm lookup', [
'activity_id' => $activity->getId(),
'team_id' => $team->getId(),
'email' => $participant->getEmailAddress(),
]);
$this->attachUserIfExists($participant, $team);
continue;
}
$records = $this->findCrmRecords($participant, $activity);
if (! empty($records)) {
$matchedRecords[] = $records;
} else {
$records = $this->findCrmDomainRecords(
crmService: $crmService,
participant: $participant,
activity: $activity,
);
if (! empty($records)) {
$matchedDomainRecords[] = $records;
}
}
if (empty($records)) {
continue;
}
try {
$activity->updateParticipantCrmData($records, $participant);
} catch (Throwable $ex) {
$this->logger->error('[CrmActivityService] Failed to update participant CRM data', [
'activity_id' => $activity->getId(),
'participant_id' => $participant->getId(),
'exception' => $ex->getMessage(),
]);
continue;
}
}
$bestMatch = $this->getBestMatch(
matchedRecords : $matchedRecords,
matchedDomainRecords: $matchedDomainRecords,
);
$this->logger->info('[CrmActivityService] CRM matching completed', [
'activity_id' => $activity->getId(),
'participants_processed' => $participants->count(),
'exact_matches' => count($matchedRecords),
'domain_matches' => count($matchedDomainRecords),
'best_match_found' => ! empty($bestMatch),
]);
return $bestMatch;
}
private function shouldPerformLookup(Participant $participant, Team $team): bool
{
if ($participant->hasEmailAddress()) {
return $this->emailHelper->shouldPerformLookup($team, $participant->getEmailAddress());
}
return true;
}
private function validateCrmConfiguration(Activity $activity): void
{
if ($activity->getCrm() === null) {
throw new InvalidArgumentException('Cannot find CRM configuration');
}
}
private function getBestMatch(?array $matchedRecords, ?array $matchedDomainRecords): array
{
return RecordSelector::pickBestFromLists($matchedRecords, $matchedDomainRecords);
}
private function findCrmRecords(Participant $participant, Activity $activity): ?array
{
$records = null;
if ($participant->hasEmailAddress()) {
$records = $this->decorator->matchExactlyByEmail(
email: $participant->getEmailAddress(),
userId: $activity->getUser()->getId()
);
}
if (empty($records) && $participant->getPhoneNumber() !== null) {
$records = $this->decorator->matchByPhone(
phone: $participant->getPhoneNumber(),
userId: $activity->getUser()->getId(),
);
}
if (empty($records) && $participant->getName() !== null) {
$records = $this->decorator->matchByName(
name: $participant->getName(),
userId: $activity->getUser()->getId(),
);
}
return $records;
}
private function shouldSkipParticipant(Participant $participant): bool
{
return $participant->hasUser();
}
private function attachUserIfExists(Participant $participant, Team $team): void
{
if ($participant->hasEmailAddress() === false) {
return;
}
$user = $this->teamRepository->findActiveTeamMemberByEmail($team, $participant->getEmailAddress());
if ($user instanceof User) {
$participant->user_id = $user->getId();
$participant->save();
}
}
private function findCrmDomainRecords(
?ServiceInterface $crmService,
Participant $participant,
Activity $activity,
): array {
if ($participant->hasEmailAddress()) {
$this->decorator->setConfiguration($activity->getCrm());
$this->decorator->setCrmService($crmService);
$records = $this->decorator->matchByDomain(
email: $participant->getEmailAddress(),
userId: $activity->getUser()->getId()
);
if (! empty($records)) {
return $records;
}
}
return [];
}
}
Sync Changes
Hide This Notification
Code changed:
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42821
|
1568
|
7
|
2026-05-14T12:05:16.912801+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760316912_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42820
|
1567
|
6
|
2026-05-14T12:05:12.790779+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760312790_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42819
|
1568
|
6
|
2026-05-14T12:04:46.546498+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760286546_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42818
|
1567
|
5
|
2026-05-14T12:04:42.489060+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760282489_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42817
|
1568
|
5
|
2026-05-14T12:04:16.133060+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760256133_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42816
|
1568
|
4
|
2026-05-14T12:03:45.759636+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760225759_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42815
|
1567
|
4
|
2026-05-14T12:03:45.418249+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760225418_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42814
|
1568
|
3
|
2026-05-14T12:03:15.388166+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760195388_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42813
|
1567
|
3
|
2026-05-14T12:03:15.121556+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760195121_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42812
|
1568
|
2
|
2026-05-14T12:02:45.010923+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760165010_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42811
|
1567
|
2
|
2026-05-14T12:02:44.786727+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760164786_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42810
|
1568
|
1
|
2026-05-14T12:02:14.513884+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760134513_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42809
|
1567
|
1
|
2026-05-14T12:02:14.433840+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760134433_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42808
|
1568
|
0
|
2026-05-14T12:01:44.170374+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760104170_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42806
|
NULL
|
NULL
|
NULL
|
|
42807
|
1567
|
0
|
2026-05-14T12:01:44.089277+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760104089_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42805
|
NULL
|
NULL
|
NULL
|
|
42806
|
NULL
|
0
|
2026-05-14T12:01:13.796279+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760073796_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7144282,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7240692,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73138297,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42805
|
NULL
|
0
|
2026-05-14T12:01:13.769625+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760073769_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7818674109799218818
|
7216084197590250280
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12077 on JY-20903-update Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42804
|
1566
|
19
|
2026-05-14T12:00:43.415663+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760043415_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Checked out JY-20903-update_activity-stage-on-oppo Checked out JY-20903-update_activity-stage-on-opportunity-change
text/html
text/html
text/html
text/html
Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Checked out JY-20903-update_activity-stage-on-opportunity-change","depth":3,"bounds":{"left":0.016954787,"top":0.858739,"width":0.1549202,"height":0.016759777},"on_screen":true,"value":"Checked out JY-20903-update_activity-stage-on-opportunity-change","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.016954787,"top":0.8603352,"width":0.027260639,"height":0.013567438},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.045877658,"top":0.8603352,"width":0.12765957,"height":0.013567438},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12566489,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7140958,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7237367,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73105055,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.07581804,"width":0.33178192,"height":0.92418194},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5862623290099894891
|
7216075401488839464
|
click
|
accessibility
|
NULL
|
Checked out JY-20903-update_activity-stage-on-oppo Checked out JY-20903-update_activity-stage-on-opportunity-change
text/html
text/html
text/html
text/html
Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42802
|
NULL
|
NULL
|
NULL
|
|
42803
|
1565
|
23
|
2026-05-14T12:00:43.426899+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760043426_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Checked out JY-20903-update_activity-stage-on-oppo Checked out JY-20903-update_activity-stage-on-opportunity-change
text/html
text/html
text/html
text/html
Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Checked out JY-20903-update_activity-stage-on-opportunity-change","depth":3,"on_screen":true,"value":"Checked out JY-20903-update_activity-stage-on-opportunity-change","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#12077 on JY-20903-update_activity-stage-on…hange, menu","depth":5,"on_screen":true,"help_text":"Pull request #12077 exists for current branch JY-20903-update__activity-stage-on…hange","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update([\n 'opportunity_id' => $opportunity->getId(),\n 'stage_id' => $opportunity->getStageId(),\n ]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5862623290099894891
|
7216075401488839464
|
click
|
accessibility
|
NULL
|
Checked out JY-20903-update_activity-stage-on-oppo Checked out JY-20903-update_activity-stage-on-opportunity-change
text/html
text/html
text/html
text/html
Project: faVsco.js, menu
#12077 on JY-20903-update_activity-stage-on…hange, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update([
'opportunity_id' => $opportunity->getId(),
'stage_id' => $opportunity->getStageId(),
]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42800
|
NULL
|
NULL
|
NULL
|
|
42802
|
1566
|
18
|
2026-05-14T12:00:36.698903+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760036698_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20903-update_activity- Project: faVsco.js, menu
JY-20903-update_activity-stage-on-opportunity-change, menu
Start Listening for PHP Debug Connections...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20903-update_activity-stage-on-opportunity-change, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12932181,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20903-update_activity-stage-on-opportunity-change","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
2309948694457577418
|
-8629521083764847645
|
visual_change
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20903-update_activity- Project: faVsco.js, menu
JY-20903-update_activity-stage-on-opportunity-change, menu
Start Listening for PHP Debug Connections
PhostormINavicarecodeFV faVsco.js°9 JY-20904-fix-update-es-orProiect vC) DeleteForCoachecComDownloaamissing lrackc rixAcuivitiesopportunitC) HaraDeleteActivitiestol© HardDeleteActivitiesTec) hyoratecalwincrmba© HydrateDefaultActivitv1C) InviteMeetinaBot.php© IterateActivities.phd© MiarateLocationFromC:© MonitorDialerActivities(C) MonitorMeetingcounte© MonitorMeetingEndCorC) MonitorMeetinostartco(t) MonitorMeetinaTrait.orC) NotifvNotLodded.oho© NotPlayableEmail.phpC) PreMeetinaNotification© PreMeetingReminder.plc) ProheMediaSeamentsel© ReassignTranscriptConC) ReindeyRecentActivitie(c) RetrvProspectsummary(C) SetProviderCanabilitiec(e) StatusCount.php© SyncMissingCallDisposi© UpdateActivityElasticS€© UpdateElasticSearch.pl•_ Analvucsw Calendars> C Hubspot› IntearationApp> C Traits© AddLavoutEntities.php© AutoloaDelavedCommaC) Backfilll@pportunitvUseiC BullhornCommandAbstC) BullhornPinaCommand.C) BullhornSearchCommarC) BullhornSessioncomma@ CheckActivitvl.cagableC) CleanDunlicateSieldDatC) 1oaActivitiesCommand@ ManageSvncStrategyC@ MatchOnnortunituAativ(C MiaratoDrovidor nhn© ProcessHubspotObject(e) DuracDelotodOnnortuniched.IV.2090/.fixcundate.ecconcactivitvcd© TextRelayService.php© ValidateSendingMessage.php© ActivityRepository.php© EventserviceProvider.pnp© StaleRecordValidator.phpC) MatchActivityCrmData.php(c) Service.php© Client.pheC) OpportunityRepository.php© UpdateSingleEntity.phpOpportunitySyncTrait.pho(C) PayloadBuilder.phpmA1л v19 04class ImportActzvityuypes implements shouldQueue* Create the event Zistener.public function __construct(private readonly ResolveTeamCrmConnection ScrmResolver,private readonly FieldRepository $fieldRepository.private readonly PlaybookCategoryRepository Srepository,1...}* Import the standard Event/Task Type picklist options from the CRMpublic function handle(PlaybookCreated $event): voidSplaybook = Sevent->[URL_WITH_CREDENTIALS] HS_local [jiminny@localhost]& console [PROD]A console (EU]in accounts cu)fii stages (EU]tid teams [EU]ImporbotkecoraingJoo.pnp© Activity.php(C) SixActivitiesOnnortunitv.nhn Xi& console SlAGiNGnamespace Jaminny console commanas Acclvicles•use ...181class FixActivitiesOpportunity extends Command20 0protected ssignature = 'activity:f1x-opportunity {--from=} 1--to=}';public function handle(EmailHelper SemailHelper): intf...}1usadeprivate function aetCrmService(Team Stean): ServiceIntenface!... }1 usaaelorivate function processParticinantsdServicelnterface ScrmService,Emal Helner SemailHelner.Activity Cactivitv): void iSteam = Sactivity->getTeamSuser = Sactivity->getUserO›Sparticipants = Sactivity->getParticipantsO:foreach (Sparticipants as $participant)if (Sparticipant->getUserId !== null || $participant->getEmailAddress === null) {continue.Sema1LAddress = Sparticipant->qetzma1lAddressO*if (SemailHelper->isCompanyEmail(Steam, SemailAddress)) {continue:try s110Sopportunitv = $this->find0pportunitvInCrm($crmService. SemailAddness. Suser->aetId@):catch (Throwable Se) 4Sthis->error( string: 'Could not find opportunity:' . $e->getMessageO):Sopportunity = nulli* Sonnontunitv === nul){iSthic->npsetActivitvlnnontunitv/Sactivitv)•continue:supoont Dally • now100% S2• Thu 14 May 15:00:36U AskJiminnyReportActivityServiceTest vPipedrive SDK EvaluaFixing Activity Stage DImport CRM Activity T+0 ..I've implemented Fix 4 in two locations:1. Activitv::updateActivitvCrmdata (lines 2122-2126).whohoif (Sopportunity d& $this->opportunity_id !== Sopportunity→>id) ‹sches→opporcuniy1o = sopporcunetyo,Reset stage id when opportunity changes to avoid stale stage from previous opportunity matchSthis->stage_id = $stage?->id;Potential Issue: If Sstage is null, this will set stage id to null even it the new opportunity has a stage in the databaseThis could happen if the CRM lookup doesn't return stage informationRecommendation: Consider checkina if the opportunity has a stage id and usina that as a fallbackO phpif Sonnortunitv ss Sthis-sonnortunitv id l== Sonnortunitv-sid)Sthis->opportunity id = sopportunity->id:to avoid stale stage from previous opportunity matchsthis->stage_id = $stage?->id ?? Sopportunity->stage_id;However, looking at the context, $stage is derived from the CRM lookup results, so if it's null, the opportunity might nothave stage intormation avallable. The current behavior is acceptable2. FixActivities0pportunitv command (lines 123-128)oho'opportunity_id' => $opportunity->getId(),'stage 1d = sopportunitv->getstage.donNo iccues found - This correctly undates hoth fielde toaetherOther locations reviewed:•IntearationApp/Service.php (line 560: Sets stage id directly from opportunity→stage id when creatina/uodatinafrom lead data - this is correct.• Copy command: Copies both opportunity id and stage id together - this is correct.• ActivityController: Handles stage id from user requests - not related to the bugTest Results• UodateCrmbataTect : 2 tests passed (6 assertions)• MatchCrm0bjectTest : 15 tests passed (75 assertions)The imolementation is sound. The only minor concern is the null stage case in updateActivitvCrmDatao, but this isaccontablo aivon tha contovtfnl .• Your included weekly usage quota is exhausted. Purchase extra usage to continue using premium models. Quota resets May 17, 11:00Lets hav÷ @Code SWF-1.6W Windsurf Toams 18.21/24 charc UTF.8io 4 spaces...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42798
|
1566
|
16
|
2026-05-14T12:00:31.830536+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760031830_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20904-fix-update-es-on-activity-command, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11070479,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20904-fix-update-es-on-activity-command","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8963127460541569662
|
-7051499938828275774
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
PhostormINavicarecodeFV faVsco.jsProiect vC) DeleteForCoachecComDownloaamissing lrackc rixAcuivitiesopportunit©) HaraDeleteActivitiesto© HardDeleteActivitiesTec) hyoratecalwincrmba© HydrateDefaultActivitv1C) InviteMeetinaBot.php© IterateActivities.phd© MiarateLocationFromC:© MonitorDialerActivities(C) MonitorMeetingcounte© MonitorMeetingEndCorC) MonitorMeetinostartco(t) MonitorMeetinaTrait.orC) NotifvNotLodded.oho© NotPlayableEmail.phpC) PreMeetinaNotification© PreMeetingReminder.plc) ProheMediaSeamentsel© ReassignTranscriptConC) ReindeyRecentActivitie(c) RetrvProspectsummary(C) SetProviderCanabilitiec(e) StatusCount.php© SyncMissingCallDisposi© UpdateActivityElasticS€© UpdateElasticSearch.pl•_ Analvucsw Calendarsyalerml> C Hubspot› IntearationApp> D Traits© AddLavoutEntities.php© AutoloaDelavedCommaC) Backfilll@pportunitvUseiC BullhornCommandAbstC) BullhornPinaCommand.C) BullhornSearchCommarC) BullhornSessioncomma@ CheckActivitvl.cagableC) CleanDunlicateSieldDatC) 1oaActivitiesCommand@ ManageSvncStrategyC@ MatchOnnortunituAativ(C MiaratoDrovidor nhn(e) DrococcHubenntOhiont(e) DuracDelotodOnnortuniched.IV.2090/.fixcundate.ecconcactivitvcd© TextRelayService.phg© ValidateSendingMessage.php© ActivityRepository.php© EventserviceProvider.pnp© StaleRecordValidator.phpC) MatchActivityCrmData.php(c) Service.php© Client.pheC) OpportunityRepository.php© UpdateSingleEntity.phpOpportunitySyncTrait.pho(C) PayloadBuilder.phpmA1 . v19 04class ImportActzvityuypes implements shouldQueue* Create the event Zistener.public function __construct(private readonly ResolveTeamCrmConnection ScrmResolver,private readonly FieldRepository $fieldRepository.private readonly PlaybookCategoryRepository Srepository,1...}* Import the standard Event/Task Type picklist options from the CRMpublic function handle(PlaybookCreated $event): voidSplaybook = Sevent->[URL_WITH_CREDENTIALS] HS_local [jiminny@localhost]& console [PROD]A console (EU]in accounts cu)fii stages (EU]tid teams [EU]ImporbotkecoraingJoo.pnp© Activity.php(C) SixActivitiesOnnortunitv.nhn Xi& console SlAGiNGnamespace Jaminny console commanas Acclvicles•use ...181class FixActivitiesOpportunity extends Command20 0protected ssignature = 'activity:f1x-opportunity {--from=} 1--to=}';public function handle(EmailHelper SemailHelper): intf...}1usadeprivate function aetCrmService(Team Stean): ServiceIntenface!... }1 usaaelorivate function processParticinantsdServicelnterface ScrmService,Emal Helner SemailHelner.Activity Cactivitv): void iSteam = Sactivity->getTeamSuser = Sactivity->getUserO›Sparticipants = Sactivity->getParticipantsO:foreach (Sparticipants as $participant)if (Sparticipant->getUserId !== null || $participant->getEmailAddress === null) {continue.Sema1LAddress = Sparticipant->qetzma1lAddressO*if (SemailHelper->isCompanyEmail(Steam, SemailAddress)) {continue:try s110Sopportunitv = $this->find0pportunitvInCrm($crmService. SemailAddness. Suser->aetId@):catch (Throwable Se) 4Sthis->error( string: 'Could not find opportunity:' . $e->getMessageO):Sopportunity = nulli* Sonnontunitv === nul){iSthic->npsetActivitvlnnontunitv/Sactivitv)•continue:supoont Dally • now100% L2• Thu 14 May 15:00:31U AskJiminnyReportActivityServiceTest vPipedrive SDK EvaluaFixing Activity Stage DImport CRM Activity T+0 ..I've implemented Fix 4 in two locations:1. Activitv::updateActivitvCrmdata (lines 2122-2126).whohoif (Sopportunity d& $this->opportunity_id !== Sopportunity→>id) ‹sches→opporcuniy1o = sopporcunetyo,Reset stage id when opportunity changes to avoid stale stage from previous opportunity matchSthis->stage_id = $stage?->id;Potential Issue: If Sstage is null, this will set stage id to null even it the new opportunity has a stage in the databaseThis could happen if the CRM lookup doesn't return stage informationRecommendation: Consider checkina if the opportunity has a stage id and usina that as a fallbackO phpif Sonnortunitv ss Sthis-sonnortunitv id l== Sonnortunitv-sid)Sthis->opportunity id = sopportunity->id:to avoid stale stage from previous opportunity matchsthis->stage_id = $stage?->id ?? Sopportunity->stage_id;However, looking at the context, $stage is derived from the CRM lookup results, so if it's null, the opportunity might nothave stage intormation avallable. The current behavior is acceptable2. FixActivities0pportunitv command (lines 123-128)oho'opportunity_id' => $opportunity->getId(),'stage 1d = sopportunitv->getstage.donNo iccues found - This correctly undates hoth fielde toaetherOther locations reviewed:•IntearationApp/Service.php (line 560: Sets stage id directly from opportunity→stage id when creatina/uodatinafrom lead data - this is correct.• Copy command: Copies both opportunity id and stage id together - this is correct.• ActivityController: Handles stage id from user requests - not related to the bugTest Results• UodateCrmbataTect : 2 tests passed (6 assertions)• MatchCrm0bjectTest : 15 tests passed (75 assertions)The imolementation is sound. The only minor concern is the null stage case in updateActivitvCrmDatao, but this isaccontablo aivon tha contovtfnl .• Your included weekly usage quota is exhausted. Purchase extra usage to continue using premium models. Quota resets May 17, 11:00Lets havl÷ @Code SWF-1.6W Windsurf Toams 18.21/24 charc UTF.8Po 4 spaces...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42797
|
1565
|
20
|
2026-05-14T12:00:31.830515+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760031830_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20904-fix-update-es-on-activity-command, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20904-fix-update-es-on-activity-command","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
2413002196346074587
|
-7048967763515953210
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
SlackFileEditViewDMsActivityLaterMoreJiminny ...# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...•- Direct messages®. Galya DimitrovaAneliya Angelova•. Vasil VasilevStefka Stoyanova&: Todor StamatovMario GeorgievNikolay Ivanov2o James Graham. Stoyan TanevSteliyan GeorgievPetko KashinskiLukas Kovalik y...::: AppsToastJira CloudConala CalaGoHistoryWindowHelp>0.(ahlSupport Daily - now→Describe what you are looking forVasil VasilevSupport Dailynow - 15:00-15:15= Notes - Support Daily.MessagesAdd canvas@ Files& Pins +ще пиша на Галя да я питам какво да правимVasil Vasilev 2:42 PMмоето е по скоро идеяв момента не го правим, но и почти не го показваме никьде като информацияние имаме някаква история на сделката, имаме стейдж по време на импорта на активититоно тоя стейдж го ползваме само за това търсене в on demand (edited)преди малко подхвърлих иначе на Галя идеята, дали да не ги покажем смените на стейджовете на сделките в deal insightsимаме дата на отваряне и затваряне на сделказащо да не сложим и един маркер кога се е променил стейджатака в таймлайна ще се вижда "развитието" на тая сделкаLukas Kovalik 2:45 PMхм ами то дали да го няма вечеVasil Vasilev 2:45 PMняма гоLukas Kovalik 2:46 PMняма дано ВЕ си го връщас тази цел точноVasil Vasilev 2:47 PMзнам, проверих, преди да предложа на Галя да ги покажемВЪЗМОЖНОно явно не е направеноMessage Vasil Vasilev+100% C8• Thu 14 May 15:00:31C Join Google Meet...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42796
|
1566
|
15
|
2026-05-14T12:00:22.129296+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760022129_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update(['opportunity_id' => $opportunity->getId()]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20904-fix-update-es-on-activity-command, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11070479,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20904-fix-update-es-on-activity-command","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7140958,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7237367,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73105055,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update(['opportunity_id' => $opportunity->getId()]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.0622506,"width":0.33178192,"height":0.9377494},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update(['opportunity_id' => $opportunity->getId()]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3491498159251776389
|
7218327201310389032
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update(['opportunity_id' => $opportunity->getId()]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options...
|
42795
|
NULL
|
NULL
|
NULL
|
|
42795
|
1566
|
14
|
2026-05-14T12:00:20.276839+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760020276_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update(['opportunity_id' => $opportunity->getId()]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20904-fix-update-es-on-activity-command, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11070479,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20904-fix-update-es-on-activity-command","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.38464096,"top":0.22426178,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"bounds":{"left":0.122340426,"top":0.16759777,"width":0.2869016,"height":0.8324022},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7140958,"top":0.12529927,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7237367,"top":0.123703115,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.73105055,"top":0.123703115,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update(['opportunity_id' => $opportunity->getId()]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"bounds":{"left":0.42985374,"top":0.0622506,"width":0.33178192,"height":0.9377494},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update(['opportunity_id' => $opportunity->getId()]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2958445655377132052
|
7218327201310389032
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update(['opportunity_id' => $opportunity->getId()]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
42794
|
1565
|
19
|
2026-05-14T12:00:20.266312+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760020266_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update(['opportunity_id' => $opportunity->getId()]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20904-fix-update-es-on-activity-command, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20904-fix-update-es-on-activity-command","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Listeners\\Crm;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Support\\Str;\nuse Jiminny\\Events\\Playbooks\\PlaybookCreated;\nuse Jiminny\\Models\\Crm\\Field;\nuse Jiminny\\Models\\Crm\\FieldValue;\nuse Jiminny\\Models\\PlaybookCategory;\nuse Jiminny\\Repositories\\Crm\\FieldRepository;\nuse Jiminny\\Repositories\\PlaybookCategoryRepository;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Services\\ResolveTeamCrmConnection;\nuse stdClass;\nuse Throwable;\n\nclass ImportActivityTypes implements ShouldQueue\n{\n /**\n * Create the event listener.\n */\n public function __construct(\n private readonly ResolveTeamCrmConnection $crmResolver,\n private readonly FieldRepository $fieldRepository,\n private readonly PlaybookCategoryRepository $repository,\n ) {\n // nothing\n }\n\n /**\n * Import the standard Event/Task Type picklist options from the CRM.\n */\n public function handle(PlaybookCreated $event): void\n {\n $playbook = $event->playbook;\n\n // Don't run if somehow we already have categories.\n if ($playbook->getCategories()->isNotEmpty()) {\n return;\n }\n\n $values = [];\n\n try {\n $crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());\n $crmService->syncField($playbook->getActivityField());\n $values = $crmService->importPicklistValues($playbook->getActivityField());\n } catch (Throwable $e) {\n Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'error' => $e->getMessage(),\n ]);\n }\n\n if (empty($values)) {\n $values = $this->fetchActivityFieldValues($playbook->getActivityField());\n\n Log::info('[ImportActivityTypes] Using database fallback for categories', [\n 'playbook_id' => $playbook->getId(),\n 'field_values_count' => $values->count(),\n ]);\n }\n\n $createdCount = 0;\n\n /** @var stdClass{label: string} $value */\n foreach ($values as $value) {\n $data = [\n 'name' => $value->label,\n 'enabled' => true,\n 'type' => PlaybookCategory::TYPE_ALL,\n ];\n\n if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;\n }\n\n if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {\n $data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;\n }\n\n $this->repository->create($playbook, $data);\n $createdCount++;\n }\n\n if ($createdCount === 0) {\n Log::warning('[ImportActivityTypes] No categories created for playbook', [\n 'playbook_id' => $playbook->getId(),\n 'team_id' => $playbook->getTeamId(),\n 'field_id' => $playbook->getActivityField()?->getId(),\n ]);\n }\n }\n\n private function fetchActivityFieldValues(Field $field): Collection\n {\n /** @var Collection<FieldValue> */\n return $this->fieldRepository->getPicklistValues($field);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update(['opportunity_id' => $opportunity->getId()]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Support\\Facades\\Validator;\nuse Jiminny\\Console\\Commands\\Command;\nuse Jiminny\\Contracts\\Services\\Crm\\ServiceInterface;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Services\\Activity\\CrmOwnerResolver;\nuse Jiminny\\Services\\Crm\\CachedCrmServiceDecorator;\nuse Jiminny\\Services\\Crm\\EmailHelper;\nuse Throwable;\n\nclass FixActivitiesOpportunity extends Command\n{\n protected $signature = 'activity:fix-opportunity {--from=} {--to=}';\n\n public function handle(EmailHelper $emailHelper): int\n {\n $from = $this->option('from');\n $to = $this->option('to');\n\n $validator = Validator::make(\n ['from' => $from, 'to' => $to],\n [\n 'from' => ['required', 'date'],\n 'to' => ['required', 'date'],\n ]\n );\n\n if ($validator->fails()) {\n $this->error('Validation failed:');\n $this->output->block($validator->errors()->all());\n\n return Command::FAILURE;\n }\n\n $this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);\n\n $activityIds = Activity::select('activities.id')\n ->whereBetween('activities.created_at', [$from, $to])\n ->join('users', 'activities.user_id', '=', 'users.id')\n ->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')\n ->whereColumn('opportunities.team_id', '<>', 'users.team_id')\n ->pluck('id');\n\n $this->info('Found activities: ' . $activityIds->count());\n\n foreach ($activityIds as $activityId) {\n $activity = Activity::where('id', $activityId)\n ->with(['user', 'participants'])\n ->first();\n\n $crmService = $this->getCrmService($activity->getTeam());\n if ($crmService === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $this->processParticipants($crmService, $emailHelper, $activity);\n }\n\n return Command::SUCCESS;\n }\n\n private function getCrmService(Team $team): ?ServiceInterface\n {\n $config = $team->getCrmConfiguration();\n\n $crmResolver = app(CrmOwnerResolver::class, [\n 'team' => $team,\n 'integrationAdmin' => $team->getOwner(),\n 'providerSlug' => $config->getProviderName(),\n ]);\n\n try {\n return $crmResolver->prepareCrmService();\n } catch (Throwable $e) {\n $this->error('Could not prepare CRM service: ' . $e->getMessage());\n\n return null;\n }\n }\n\n private function processParticipants(\n ServiceInterface $crmService,\n EmailHelper $emailHelper,\n Activity $activity\n ): void {\n $team = $activity->getTeam();\n $user = $activity->getUser();\n $participants = $activity->getParticipants();\n\n foreach ($participants as $participant) {\n if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {\n continue;\n }\n\n $emailAddress = $participant->getEmailAddress();\n if ($emailHelper->isCompanyEmail($team, $emailAddress)) {\n continue;\n }\n\n try {\n $opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());\n } catch (Throwable $e) {\n $this->error('Could not find opportunity: ' . $e->getMessage());\n\n $opportunity = null;\n }\n\n if ($opportunity === null) {\n $this->resetActivityOpportunity($activity);\n\n continue;\n }\n\n $activity->update(['opportunity_id' => $opportunity->getId()]);\n\n $this->info('Opportunity updated for activity: ' . $activity->getId());\n }\n }\n\n private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity\n {\n $decorator = resolve(CachedCrmServiceDecorator::class);\n $decorator->setCrmService($crmService);\n\n $match = $decorator->matchExactlyByEmail($emailAddress, $userId);\n\n if (empty($match)) {\n $match = $decorator->matchByDomain($emailAddress, $userId);\n }\n\n if (empty($match)) {\n return null;\n }\n\n [, , $opportunity, ,] = $match;\n\n return $opportunity;\n }\n\n private function resetActivityOpportunity(Activity $activity): void\n {\n $this->info('Reset opportunity for activity: ' . $activity->getId());\n $activity->update(['opportunity_id' => null]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2958445655377132052
|
7218327201310389032
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20904-fix-update-es-on Project: faVsco.js, menu
JY-20904-fix-update-es-on-activity-command, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Listeners\Crm;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Jiminny\Events\Playbooks\PlaybookCreated;
use Jiminny\Models\Crm\Field;
use Jiminny\Models\Crm\FieldValue;
use Jiminny\Models\PlaybookCategory;
use Jiminny\Repositories\Crm\FieldRepository;
use Jiminny\Repositories\PlaybookCategoryRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Jiminny\Services\ResolveTeamCrmConnection;
use stdClass;
use Throwable;
class ImportActivityTypes implements ShouldQueue
{
/**
* Create the event listener.
*/
public function __construct(
private readonly ResolveTeamCrmConnection $crmResolver,
private readonly FieldRepository $fieldRepository,
private readonly PlaybookCategoryRepository $repository,
) {
// nothing
}
/**
* Import the standard Event/Task Type picklist options from the CRM.
*/
public function handle(PlaybookCreated $event): void
{
$playbook = $event->playbook;
// Don't run if somehow we already have categories.
if ($playbook->getCategories()->isNotEmpty()) {
return;
}
$values = [];
try {
$crmService = $this->crmResolver->resolveForTeam($playbook->getTeam());
$crmService->syncField($playbook->getActivityField());
$values = $crmService->importPicklistValues($playbook->getActivityField());
} catch (Throwable $e) {
Log::warning('[ImportActivityTypes] CRM API failed, falling back to database values', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'error' => $e->getMessage(),
]);
}
if (empty($values)) {
$values = $this->fetchActivityFieldValues($playbook->getActivityField());
Log::info('[ImportActivityTypes] Using database fallback for categories', [
'playbook_id' => $playbook->getId(),
'field_values_count' => $values->count(),
]);
}
$createdCount = 0;
/** @var stdClass{label: string} $value */
foreach ($values as $value) {
$data = [
'name' => $value->label,
'enabled' => true,
'type' => PlaybookCategory::TYPE_ALL,
];
if (Str::contains(strtolower($value->label), ['sms sent', 'sms out', 'text in'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_OUTBOUND;
}
if (Str::contains(strtolower($value->label), ['sms received', 'sms in', 'text out'])) {
$data['type'] = PlaybookCategory::TYPE_SMS_INBOUND;
}
$this->repository->create($playbook, $data);
$createdCount++;
}
if ($createdCount === 0) {
Log::warning('[ImportActivityTypes] No categories created for playbook', [
'playbook_id' => $playbook->getId(),
'team_id' => $playbook->getTeamId(),
'field_id' => $playbook->getActivityField()?->getId(),
]);
}
}
private function fetchActivityFieldValues(Field $field): Collection
{
/** @var Collection<FieldValue> */
return $this->fieldRepository->getPicklistValues($field);
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Support\Facades\Validator;
use Jiminny\Console\Commands\Command;
use Jiminny\Contracts\Services\Crm\ServiceInterface;
use Jiminny\Models\Activity;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Team;
use Jiminny\Services\Activity\CrmOwnerResolver;
use Jiminny\Services\Crm\CachedCrmServiceDecorator;
use Jiminny\Services\Crm\EmailHelper;
use Throwable;
class FixActivitiesOpportunity extends Command
{
protected $signature = 'activity:fix-opportunity {--from=} {--to=}';
public function handle(EmailHelper $emailHelper): int
{
$from = $this->option('from');
$to = $this->option('to');
$validator = Validator::make(
['from' => $from, 'to' => $to],
[
'from' => ['required', 'date'],
'to' => ['required', 'date'],
]
);
if ($validator->fails()) {
$this->error('Validation failed:');
$this->output->block($validator->errors()->all());
return Command::FAILURE;
}
$this->info('Fixing opportunity for activities from ' . $from . ' to ' . $to);
$activityIds = Activity::select('activities.id')
->whereBetween('activities.created_at', [$from, $to])
->join('users', 'activities.user_id', '=', 'users.id')
->join('opportunities', 'activities.opportunity_id', '=', 'opportunities.id')
->whereColumn('opportunities.team_id', '<>', 'users.team_id')
->pluck('id');
$this->info('Found activities: ' . $activityIds->count());
foreach ($activityIds as $activityId) {
$activity = Activity::where('id', $activityId)
->with(['user', 'participants'])
->first();
$crmService = $this->getCrmService($activity->getTeam());
if ($crmService === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$this->processParticipants($crmService, $emailHelper, $activity);
}
return Command::SUCCESS;
}
private function getCrmService(Team $team): ?ServiceInterface
{
$config = $team->getCrmConfiguration();
$crmResolver = app(CrmOwnerResolver::class, [
'team' => $team,
'integrationAdmin' => $team->getOwner(),
'providerSlug' => $config->getProviderName(),
]);
try {
return $crmResolver->prepareCrmService();
} catch (Throwable $e) {
$this->error('Could not prepare CRM service: ' . $e->getMessage());
return null;
}
}
private function processParticipants(
ServiceInterface $crmService,
EmailHelper $emailHelper,
Activity $activity
): void {
$team = $activity->getTeam();
$user = $activity->getUser();
$participants = $activity->getParticipants();
foreach ($participants as $participant) {
if ($participant->getUserId() !== null || $participant->getEmailAddress() === null) {
continue;
}
$emailAddress = $participant->getEmailAddress();
if ($emailHelper->isCompanyEmail($team, $emailAddress)) {
continue;
}
try {
$opportunity = $this->findOpportunityInCrm($crmService, $emailAddress, $user->getId());
} catch (Throwable $e) {
$this->error('Could not find opportunity: ' . $e->getMessage());
$opportunity = null;
}
if ($opportunity === null) {
$this->resetActivityOpportunity($activity);
continue;
}
$activity->update(['opportunity_id' => $opportunity->getId()]);
$this->info('Opportunity updated for activity: ' . $activity->getId());
}
}
private function findOpportunityInCrm(ServiceInterface $crmService, string $emailAddress, int $userId): ?Opportunity
{
$decorator = resolve(CachedCrmServiceDecorator::class);
$decorator->setCrmService($crmService);
$match = $decorator->matchExactlyByEmail($emailAddress, $userId);
if (empty($match)) {
$match = $decorator->matchByDomain($emailAddress, $userId);
}
if (empty($match)) {
return null;
}
[, , $opportunity, ,] = $match;
return $opportunity;
}
private function resetActivityOpportunity(Activity $activity): void
{
$this->info('Reset opportunity for activity: ' . $activity->getId());
$activity->update(['opportunity_id' => null]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
42793
|
NULL
|
NULL
|
NULL
|
|
42793
|
1565
|
18
|
2026-05-14T12:00:16.046467+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778760016046_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewDMsActivityLaterMoreJiminny ...# SlackFileEditViewDMsActivityLaterMoreJiminny ...# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...•- Direct messages®. Galya DimitrovaAneliya Angelova•. Vasil VasilevStefka Stoyanova&: Todor StamatovMario GeorgievNikolay Ivanov2o James Graham. Stoyan TanevSteliyan GeorgievPetko KashinskiLukas Kovalik y...::: AppsToastJira CloudConala CalaGoHistoryWindowHelp>0.(ahlSupport Daily - now→Describe what you are looking forVasil VasilevSupport Dailynow - 15:00-15:15= Notes - Support Daily.MessagesAdd canvas@ Files& Pins +ще пиша на Галя да я питам какво да правимVasil Vasilev 2:42 PMмоето е по скоро идеяв момента не го правим, но и почти не го показваме никьде като информацияние имаме някаква история на сделката, имаме стейдж по време на импорта на активититоно тоя стейдж го ползваме само за това търсене в on demand (edited)преди малко подхвърлих иначе на Галя идеята, дали да не ги покажем смените на стейджовете на сделките в deal insightsимаме дата на отваряне и затваряне на сделказащо да не сложим и един маркер кога се е променил стейджатака в таймлайна ще се вижда "развитието" на тая сделкаLukas Kovalik 2:45 PMхм ами то дали да го няма вечеVasil Vasilev 2:45 PMняма гоLukas Kovalik 2:46 PMняма дано ВЕ си го връщас тази цел точноVasil Vasilev 2:47 PMзнам, проверих, преди да предложа на Галя да ги покажемВЪЗМОЖНОно явно не е направеноMessage Vasil Vasilev+100% C8• Thu 14 May 15:00:15C Join Google Meet...
|
NULL
|
98455502234825243
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewDMsActivityLaterMoreJiminny ...# SlackFileEditViewDMsActivityLaterMoreJiminny ...# engineering# general# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...•- Direct messages®. Galya DimitrovaAneliya Angelova•. Vasil VasilevStefka Stoyanova&: Todor StamatovMario GeorgievNikolay Ivanov2o James Graham. Stoyan TanevSteliyan GeorgievPetko KashinskiLukas Kovalik y...::: AppsToastJira CloudConala CalaGoHistoryWindowHelp>0.(ahlSupport Daily - now→Describe what you are looking forVasil VasilevSupport Dailynow - 15:00-15:15= Notes - Support Daily.MessagesAdd canvas@ Files& Pins +ще пиша на Галя да я питам какво да правимVasil Vasilev 2:42 PMмоето е по скоро идеяв момента не го правим, но и почти не го показваме никьде като информацияние имаме някаква история на сделката, имаме стейдж по време на импорта на активититоно тоя стейдж го ползваме само за това търсене в on demand (edited)преди малко подхвърлих иначе на Галя идеята, дали да не ги покажем смените на стейджовете на сделките в deal insightsимаме дата на отваряне и затваряне на сделказащо да не сложим и един маркер кога се е променил стейджатака в таймлайна ще се вижда "развитието" на тая сделкаLukas Kovalik 2:45 PMхм ами то дали да го няма вечеVasil Vasilev 2:45 PMняма гоLukas Kovalik 2:46 PMняма дано ВЕ си го връщас тази цел точноVasil Vasilev 2:47 PMзнам, проверих, преди да предложа на Галя да ги покажемВЪЗМОЖНОно явно не е направеноMessage Vasil Vasilev+100% C8• Thu 14 May 15:00:15C Join Google Meet...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
41042
|
1515
|
14
|
2026-05-14T09:44:28.999521+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751868999_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
FirefoxFileEditViewHistoryBookmarksProfilesCTools FirefoxFileEditViewHistoryBookmarksProfilesCTools WindowHelpmeet.google.com/mie-gawc-dsi?authuser=lukas.kovalik%40jiminny.com>0 lhl • | Daily - Platform - now+100% <478•Thu 14 May 9:45:36...
|
NULL
|
-708492635982512963
|
NULL
|
click
|
ocr
|
NULL
|
FirefoxFileEditViewHistoryBookmarksProfilesCTools FirefoxFileEditViewHistoryBookmarksProfilesCTools WindowHelpmeet.google.com/mie-gawc-dsi?authuser=lukas.kovalik%40jiminny.com>0 lhl • | Daily - Platform - now+100% <478•Thu 14 May 9:45:36...
|
41040
|
NULL
|
NULL
|
NULL
|
|
41041
|
1516
|
13
|
2026-05-14T09:44:26.984814+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751866984_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
slackw Usage | Windsurf• JY-20891 add support for slackw Usage | Windsurf• JY-20891 add support for second:[SRD-6848] Sidekick SMS issue -Platform Sprint 4 Q2 - Platform TeDependabot alerts • jiminny/proph(JY-19958] Upgrade BE librariesWY-20773) User Pilot not receivini( JY-19957 | Remove abanded sympTypeError: Leaque|Flysystem\Files1. Userpilot I Ask Jiminny Report Gen[JY-19957] Upgrade BE libraries -Dependabot alerts - iminny/app11Y-208011 Sidekick SMS iccue -[SRD-6849] Recorded call does n8 Jiminnv8 Jiminny8 Jiminny* Configure SSH access to multiple≥ Useful conDev Tools - ElasticJiminny-7 (SRD-68531 Moxso - Potential des& CloudWatch I eu-west-1CloudWatch | eu-west-1Platform Sorint 4 02 - Platform TeJY-20891 add support for secondaService-Desk - Queues - Platfc XIL Now TohMIStOMwindowhelg1y.dulasslan.nelIld/servicedesk/oroeeJ JIMINNYg For you(• RecentSpaces / Service-Desk / QueuesPlatform team* Starred0+ Apps|:= ListQ SpacesQ Search workJiminny (New)s work lems14 Service-DeskKeyE QueuesSRD-6853Team Priority|©, All open tickets 12SRD-68495 Unassigned t... 3Ej Support tea….SpN-69A9•, Raised by meE Assigned to ..Ej Service requ..E Plattorm teamE Processing t...Ej Site reliability... 0•, New features... 0bi InfoSec issues 0j Ready for Cu... 0•1 Resolved ti….. 999+= View all queuesF Service requestsA IncidentsHl ReportsC Operations• Knowledae Base0 Customers• Channolel• Email loasI< Develoner escalationsl: Slack integration< Reporting Center• Search IRequest tvpe vStatus vAssianee vSummaryMoxso - Potential deal stages bugkecorded call does not aobear on the casnooaroSidekick SMS issueMore tilters vPriority levelP2 MediumPe MediumP2 MediumHomeDMSActivityLateMoreJiminny...yS Starred8 jiminny-x-integrati…..•olattorm-inner-teamE) Channels# ai-chapter# alerts# backend# bugs# confusion-clinid# curiosity lab# engineering# general# jiminny-bg# platform-tickets# product launches# randomi released# sofia-officea suodort# thank-yous# the people of iimi..A Direct messages• Vasil VasilevM Stefka StovanovaMario GeorgievNikolav Ivanovo James Graham8 Stovan Tanev© Galva DimitrovaStelivan Georgiey( Petko KashinskiR Aneliva Angelova EFa Lukas Kovali#: AppsS lira GloudToastm) Google Cale!YDally - Plau100% 1∞' Inu 14 May 9:40:30@ Describe what you are looking for& e. Vasil Vasilev• MessagestAdd canvas( FilesX Pins+1 new messageVasil Vasilley 9.39 AMIдобро утровчера забравих за тебопоави ли се с инлексите, или оше ти липоват ланнииначе имах прелвлиmake docker-updateи реоилдване на локалните контеинерипри мен преди време се бе случило така, че не върваха процесите за индексиране, понеже es-update-worker-а лиспвашеа пьк менажирането на тея процеси от scheduler беше спряноLukas Kovalik 9:42 AMоправих се, но трябваше да пипна команда ще намираше грешно активитиVasi Vasiley 9•43 AMкакьв беше точно проблема всъшност?Lukas Kovalik # 9:43 AMiny# php artisan activity:update:es 422003rouna aeloieysu.s, u. уooовасато 5аоeesending activity tor ts update..Done.това е вече с повече логове422003 -> 16трябва да го видя ощеVasil Vasiley 9:44 ANSactivity = Activity::id0rUuId(SactivityId)->firstO;това е пооблема.Lukas Kovalik 9:44.AMVasil Vasilev 9:44 AMActivity:.dOrludsactivitvicheтова само по себе си връша правилния моделобаче като извикаш върху Activity инстанция допълнтиелно ->first()бюка чаново в базата и рзима пиориа спошнат запискоито винаги в най ниското И ліMessage Vasil Vasilev+ Аal...
|
NULL
|
8912455784959274687
|
NULL
|
app_switch
|
ocr
|
NULL
|
slackw Usage | Windsurf• JY-20891 add support for slackw Usage | Windsurf• JY-20891 add support for second:[SRD-6848] Sidekick SMS issue -Platform Sprint 4 Q2 - Platform TeDependabot alerts • jiminny/proph(JY-19958] Upgrade BE librariesWY-20773) User Pilot not receivini( JY-19957 | Remove abanded sympTypeError: Leaque|Flysystem\Files1. Userpilot I Ask Jiminny Report Gen[JY-19957] Upgrade BE libraries -Dependabot alerts - iminny/app11Y-208011 Sidekick SMS iccue -[SRD-6849] Recorded call does n8 Jiminnv8 Jiminny8 Jiminny* Configure SSH access to multiple≥ Useful conDev Tools - ElasticJiminny-7 (SRD-68531 Moxso - Potential des& CloudWatch I eu-west-1CloudWatch | eu-west-1Platform Sorint 4 02 - Platform TeJY-20891 add support for secondaService-Desk - Queues - Platfc XIL Now TohMIStOMwindowhelg1y.dulasslan.nelIld/servicedesk/oroeeJ JIMINNYg For you(• RecentSpaces / Service-Desk / QueuesPlatform team* Starred0+ Apps|:= ListQ SpacesQ Search workJiminny (New)s work lems14 Service-DeskKeyE QueuesSRD-6853Team Priority|©, All open tickets 12SRD-68495 Unassigned t... 3Ej Support tea….SpN-69A9•, Raised by meE Assigned to ..Ej Service requ..E Plattorm teamE Processing t...Ej Site reliability... 0•, New features... 0bi InfoSec issues 0j Ready for Cu... 0•1 Resolved ti….. 999+= View all queuesF Service requestsA IncidentsHl ReportsC Operations• Knowledae Base0 Customers• Channolel• Email loasI< Develoner escalationsl: Slack integration< Reporting Center• Search IRequest tvpe vStatus vAssianee vSummaryMoxso - Potential deal stages bugkecorded call does not aobear on the casnooaroSidekick SMS issueMore tilters vPriority levelP2 MediumPe MediumP2 MediumHomeDMSActivityLateMoreJiminny...yS Starred8 jiminny-x-integrati…..•olattorm-inner-teamE) Channels# ai-chapter# alerts# backend# bugs# confusion-clinid# curiosity lab# engineering# general# jiminny-bg# platform-tickets# product launches# randomi released# sofia-officea suodort# thank-yous# the people of iimi..A Direct messages• Vasil VasilevM Stefka StovanovaMario GeorgievNikolav Ivanovo James Graham8 Stovan Tanev© Galva DimitrovaStelivan Georgiey( Petko KashinskiR Aneliva Angelova EFa Lukas Kovali#: AppsS lira GloudToastm) Google Cale!YDally - Plau100% 1∞' Inu 14 May 9:40:30@ Describe what you are looking for& e. Vasil Vasilev• MessagestAdd canvas( FilesX Pins+1 new messageVasil Vasilley 9.39 AMIдобро утровчера забравих за тебопоави ли се с инлексите, или оше ти липоват ланнииначе имах прелвлиmake docker-updateи реоилдване на локалните контеинерипри мен преди време се бе случило така, че не върваха процесите за индексиране, понеже es-update-worker-а лиспвашеа пьк менажирането на тея процеси от scheduler беше спряноLukas Kovalik 9:42 AMоправих се, но трябваше да пипна команда ще намираше грешно активитиVasi Vasiley 9•43 AMкакьв беше точно проблема всъшност?Lukas Kovalik # 9:43 AMiny# php artisan activity:update:es 422003rouna aeloieysu.s, u. уooовасато 5аоeesending activity tor ts update..Done.това е вече с повече логове422003 -> 16трябва да го видя ощеVasil Vasiley 9:44 ANSactivity = Activity::id0rUuId(SactivityId)->firstO;това е пооблема.Lukas Kovalik 9:44.AMVasil Vasilev 9:44 AMActivity:.dOrludsactivitvicheтова само по себе си връша правилния моделобаче като извикаш върху Activity инстанция допълнтиелно ->first()бюка чаново в базата и рзима пиориа спошнат запискоито винаги в най ниското И ліMessage Vasil Vasilev+ Аal...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
41040
|
1515
|
13
|
2026-05-14T09:44:26.988804+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751866988_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8043719072324535154
|
-8628527368849355612
|
app_switch
|
hybrid
|
NULL
|
Project: faVsco.js, menu
FirefoxFileEditViewHistor Project: faVsco.js, menu
FirefoxFileEditViewHistoryBookmarksProfilesCTools WindowHelpmeet.google.com/mie-gawc-dsi?authuser=lukas.kovalik%40jiminny.com>0 lhl • | Daily - Platform - now+100% <478•Thu 14 May 9:45:36...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
40905
|
1512
|
6
|
2026-05-14T09:33:19.593526+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751199593_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
slackw Usage | Windsurf• JY-20891 add support for slackw Usage | Windsurf• JY-20891 add support for second:[SRD-6848] Sidekick SMS issue -Platform Sprint 4 Q2 - Platform TeDependabot alerts • jiminny/proph(JY-19958] Upgrade BE librariesWY-20773) User Pilot not receivini( JY-19957 | Remove abanded sympTypeError: Leaque|Flysystem\Files1. Userpilot I Ask Jiminny Report Gen[JY-19957] Upgrade BE libraries -Dependabot alerts - iminny/app11Y-208011 Sidekick SMS iccue -[SRD-6849] Recorded call does n8 Jiminnv8 Jiminny8 Jiminny* Configure SSH access to multiple≥ Useful conDev Tools - ElasticJiminny-7 (SRD-68531 Moxso - Potential des& CloudWatch I eu-west-1CloudWatch | eu-west-1Platform Sorint 4 02 - Platform TeJY-20891 add support for secondaService-Desk - Queues - Platfc XIL Now TohMIStOMwindowhelg1y.dulasslan.nelIld/servicedesk/oroeeJ JIMINNYg For you(• RecentSpaces / Service-Desk / QueuesPlatform team* Starred0+ Apps|:= ListQ SpacesQ Search workJiminny (New)s work lems14 Service-DeskKeyE QueuesSRD-6853Team Priority|©, All open tickets 12SRD-68495 Unassigned t... 3Ej Support tea….SpN-69A9•, Raised by meE Assigned to ..Ej Service requ..E Plattorm teamE Processing t...Ej Site reliability... 0•, New features... 0bi InfoSec issues 0j Ready for Cu... 0•1 Resolved ti….. 999+= View all queuesF Service requestsA IncidentsHl ReportsC Operations• Knowledae Base0 Customers• Channolel• Email loasI< Develoner escalationsl: Slack integration< Reporting Center• Search IRequest tvpe vStatus vAssianee vSummaryMoxso - Potential deal stages bugkecorded call does not aobear on the casnooaroSidekick SMS issueMore tilters vPriority levelP2 MediumPe MediumP2 MediumHomeDMSActivityLateMoreJiminny...yS Starred8 jiminny-x-integrati…..•olattorm-inner-teamE) Channels# ai-chapter# alerts# backend# bugs# confusion-clinid# curiosity lab# engineering# general# jiminny-bg# platform-tickets# product launches# randomi released# sofia-officea suodort# thank-yous# the people of iimi..A Direct messages• Vasil VasilevM Stefka StovanovaMario GeorgievNikolav Ivanovo James Graham8 Stovan Tanev© Galva DimitrovaStelivan Georgiey( Petko KashinskiR Aneliva Angelova EFa Lukas Kovali#: AppsS lira GloudToastm) Google Cale!YDally - Plau100% 1∞' Inu 14 May 9:40:30@ Describe what you are looking for& e. Vasil Vasilev• MessagestAdd canvas( FilesX Pins+1 new messageVasil Vasilley 9.39 AMIдобро утровчера забравих за тебопоави ли се с инлексите, или оше ти липоват ланнииначе имах прелвлиmake docker-updateи реоилдване на локалните контеинерипри мен преди време се бе случило така, че не върваха процесите за индексиране, понеже es-update-worker-а лиспвашеа пьк менажирането на тея процеси от scheduler беше спряноLukas Kovalik 9:42 AMоправих се, но трябваше да пипна команда ще намираше грешно активитиVasi Vasiley 9•43 AMкакьв беше точно проблема всъшност?Lukas Kovalik # 9:43 AMiny# php artisan activity:update:es 422003rouna aeloieysu.s, u. уooовасато 5аоeesending activity tor ts update..Done.това е вече с повече логове422003 -> 16трябва да го видя ощеVasil Vasiley 9:44 ANSactivity = Activity::id0rUuId(SactivityId)->firstO;това е пооблема.Lukas Kovalik 9:44.AMVasil Vasilev 9:44 AMActivity:.dOrludsactivitvicheтова само по себе си връша правилния моделобаче като извикаш върху Activity инстанция допълнтиелно ->first()бюка чаново в базата и рзима пиориа спошнат запискоито винаги в най ниското И ліMessage Vasil Vasilev+ Аal...
|
NULL
|
8912455784959274687
|
NULL
|
click
|
ocr
|
NULL
|
slackw Usage | Windsurf• JY-20891 add support for slackw Usage | Windsurf• JY-20891 add support for second:[SRD-6848] Sidekick SMS issue -Platform Sprint 4 Q2 - Platform TeDependabot alerts • jiminny/proph(JY-19958] Upgrade BE librariesWY-20773) User Pilot not receivini( JY-19957 | Remove abanded sympTypeError: Leaque|Flysystem\Files1. Userpilot I Ask Jiminny Report Gen[JY-19957] Upgrade BE libraries -Dependabot alerts - iminny/app11Y-208011 Sidekick SMS iccue -[SRD-6849] Recorded call does n8 Jiminnv8 Jiminny8 Jiminny* Configure SSH access to multiple≥ Useful conDev Tools - ElasticJiminny-7 (SRD-68531 Moxso - Potential des& CloudWatch I eu-west-1CloudWatch | eu-west-1Platform Sorint 4 02 - Platform TeJY-20891 add support for secondaService-Desk - Queues - Platfc XIL Now TohMIStOMwindowhelg1y.dulasslan.nelIld/servicedesk/oroeeJ JIMINNYg For you(• RecentSpaces / Service-Desk / QueuesPlatform team* Starred0+ Apps|:= ListQ SpacesQ Search workJiminny (New)s work lems14 Service-DeskKeyE QueuesSRD-6853Team Priority|©, All open tickets 12SRD-68495 Unassigned t... 3Ej Support tea….SpN-69A9•, Raised by meE Assigned to ..Ej Service requ..E Plattorm teamE Processing t...Ej Site reliability... 0•, New features... 0bi InfoSec issues 0j Ready for Cu... 0•1 Resolved ti….. 999+= View all queuesF Service requestsA IncidentsHl ReportsC Operations• Knowledae Base0 Customers• Channolel• Email loasI< Develoner escalationsl: Slack integration< Reporting Center• Search IRequest tvpe vStatus vAssianee vSummaryMoxso - Potential deal stages bugkecorded call does not aobear on the casnooaroSidekick SMS issueMore tilters vPriority levelP2 MediumPe MediumP2 MediumHomeDMSActivityLateMoreJiminny...yS Starred8 jiminny-x-integrati…..•olattorm-inner-teamE) Channels# ai-chapter# alerts# backend# bugs# confusion-clinid# curiosity lab# engineering# general# jiminny-bg# platform-tickets# product launches# randomi released# sofia-officea suodort# thank-yous# the people of iimi..A Direct messages• Vasil VasilevM Stefka StovanovaMario GeorgievNikolav Ivanovo James Graham8 Stovan Tanev© Galva DimitrovaStelivan Georgiey( Petko KashinskiR Aneliva Angelova EFa Lukas Kovali#: AppsS lira GloudToastm) Google Cale!YDally - Plau100% 1∞' Inu 14 May 9:40:30@ Describe what you are looking for& e. Vasil Vasilev• MessagestAdd canvas( FilesX Pins+1 new messageVasil Vasilley 9.39 AMIдобро утровчера забравих за тебопоави ли се с инлексите, или оше ти липоват ланнииначе имах прелвлиmake docker-updateи реоилдване на локалните контеинерипри мен преди време се бе случило така, че не върваха процесите за индексиране, понеже es-update-worker-а лиспвашеа пьк менажирането на тея процеси от scheduler беше спряноLukas Kovalik 9:42 AMоправих се, но трябваше да пипна команда ще намираше грешно активитиVasi Vasiley 9•43 AMкакьв беше точно проблема всъшност?Lukas Kovalik # 9:43 AMiny# php artisan activity:update:es 422003rouna aeloieysu.s, u. уooовасато 5аоeesending activity tor ts update..Done.това е вече с повече логове422003 -> 16трябва да го видя ощеVasil Vasiley 9:44 ANSactivity = Activity::id0rUuId(SactivityId)->firstO;това е пооблема.Lukas Kovalik 9:44.AMVasil Vasilev 9:44 AMActivity:.dOrludsactivitvicheтова само по себе си връша правилния моделобаче като извикаш върху Activity инстанция допълнтиелно ->first()бюка чаново в базата и рзима пиориа спошнат запискоито винаги в най ниското И ліMessage Vasil Vasilev+ Аal...
|
40903
|
NULL
|
NULL
|
NULL
|
|
40904
|
1511
|
3
|
2026-05-14T09:33:19.593537+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751199593_m1.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
FirefoxFileEditViewHistoryBookmarksProfilesCTools FirefoxFileEditViewHistoryBookmarksProfilesCTools WindowHelpmeet.google.com/mie-gawc-dsi?authuser=lukas.kovalik%40jiminny.com>0 lhl • | Daily - Platform - now+100% <478•Thu 14 May 9:45:36...
|
NULL
|
-708492635982512963
|
NULL
|
click
|
ocr
|
NULL
|
FirefoxFileEditViewHistoryBookmarksProfilesCTools FirefoxFileEditViewHistoryBookmarksProfilesCTools WindowHelpmeet.google.com/mie-gawc-dsi?authuser=lukas.kovalik%40jiminny.com>0 lhl • | Daily - Platform - now+100% <478•Thu 14 May 9:45:36...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
40903
|
1512
|
5
|
2026-05-14T09:32:38.486544+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751158486_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20903-update_activity- Project: faVsco.js, menu
JY-20903-update_activity-stage-on-opportunity-change, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20903-update_activity-stage-on-opportunity-change, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12932181,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20903-update_activity-stage-on-opportunity-change","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
1204437775102933237
|
587086757554801091
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20903-update_activity- Project: faVsco.js, menu
JY-20903-update_activity-stage-on-opportunity-change, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
slackw Usage | Windsurf• JY-20891 add support for second:[SRD-6848] Sidekick SMS issue -Platform Sprint 4 Q2 - Platform TeDependabot alerts • jiminny/proph(JY-19958] Upgrade BE librariesWY-20773) User Pilot not receivini( JY-19957 | Remove abanded sympTypeError: Leaque|Flysystem\Files1. Userpilot I Ask Jiminny Report Gen[JY-19957] Upgrade BE libraries -Dependabot alerts - iminny/app11Y-208011 Sidekick SMS iccue -[SRD-6849] Recorded call does n8 Jiminnv8 Jiminny8 Jiminny* Configure SSH access to multiple≥ Useful conDev Tools - ElasticJiminny-7 (SRD-68531 Moxso - Potential des& CloudWatch I eu-west-1CloudWatch | eu-west-1Platform Sorint 4 02 - Platform TeJY-20891 add support for secondaService-Desk - Queues - Platfc XIL Now TohMIStOMwindowhelg1y.dulasslan.nelIld/servicedesk/oroeeJ JIMINNYg For you(• RecentSpaces / Service-Desk / QueuesPlatform team* Starred0+ Apps|:= ListQ SpacesQ Search workJiminny (New)s work lems14 Service-DeskKeyE QueuesSRD-6853Team Priority|©, All open tickets 12SRD-68495 Unassigned t... 3Ej Support tea….SpN-69A9•, Raised by meE Assigned to ..Ej Service requ..E Plattorm teamE Processing t...Ej Site reliability... 0•, New features... 0bi InfoSec issues 0j Ready for Cu... 0•1 Resolved ti….. 999+= View all queuesF Service requestsA IncidentsHl ReportsC Operations• Knowledae Base0 Customers• Channolel• Email loasI< Develoner escalationsl: Slack integration< Reporting Center• Search IRequest tvpe vStatus vAssianee vSummaryMoxso - Potential deal stages bugkecorded call does not aobear on the casnooaroSidekick SMS issueMore tilters vPriority levelP2 MediumPe MediumP2 MediumHomeDMSActivityLateMoreJiminny...yS Starred8 jiminny-x-integrati…..•olattorm-inner-teamE) Channels# ai-chapter# alerts# backend# bugs# confusion-clinid# curiosity lab# engineering# general# jiminny-bg# platform-tickets# product launches# randomi released# sofia-officea suodort# thank-yous# the people of iimi..A Direct messages• Vasil VasilevM Stefka StovanovaMario GeorgievNikolav Ivanovo James Graham8 Stovan Tanev© Galva DimitrovaStelivan Georgiey( Petko KashinskiR Aneliva Angelova EFa Lukas Kovali#: AppsS lira GloudToastm) Google Cale!YDally - Plau100% 1∞' Inu 14 May 9:40:30@ Describe what you are looking for& e. Vasil Vasilev• MessagestAdd canvas( FilesX Pins+1 new messageVasil Vasilley 9.39 AMIдобро утровчера забравих за тебопоави ли се с инлексите, или оше ти липоват ланнииначе имах прелвлиmake docker-updateи реоилдване на локалните контеинерипри мен преди време се бе случило така, че не върваха процесите за индексиране, понеже es-update-worker-а лиспвашеа пьк менажирането на тея процеси от scheduler беше спряноLukas Kovalik 9:42 AMоправих се, но трябваше да пипна команда ще намираше грешно активитиVasi Vasiley 9•43 AMкакьв беше точно проблема всъшност?Lukas Kovalik # 9:43 AMiny# php artisan activity:update:es 422003rouna aeloieysu.s, u. уooовасато 5аоeesending activity tor ts update..Done.това е вече с повече логове422003 -> 16трябва да го видя ощеVasil Vasiley 9:44 ANSactivity = Activity::id0rUuId(SactivityId)->firstO;това е пооблема.Lukas Kovalik 9:44.AMVasil Vasilev 9:44 AMActivity:.dOrludsactivitvicheтова само по себе си връша правилния моделобаче като извикаш върху Activity инстанция допълнтиелно ->first()бюка чаново в базата и рзима пиориа спошнат запискоито винаги в най ниското И ліMessage Vasil Vasilev+ Аal...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
40902
|
1512
|
4
|
2026-05-14T09:32:35.272010+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-14/1778 /Users/lukas/.screenpipe/data/data/2026-05-14/1778751155272_m2.jpg...
|
PhpStorm
|
faVsco.js – FixActivitiesOpportunity.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20903-update_activity- Project: faVsco.js, menu
JY-20903-update_activity-stage-on-opportunity-change, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
7
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
use Jiminny\Contracts\ES\Events\UpdateSingleEntity;
use Jiminny\Contracts\ES\UpdateTargetEnum;
use Jiminny\Models\Activity;
class UpdateActivityElasticSearchDocumentCommand extends Command
{
protected $signature = 'activity:update:es {activityId}';
protected $description = 'Update ES document synchronously';
public function __construct(private readonly Dispatcher $eventDispatcher)
{
parent::__construct();
}
public function handle(): void
{
$activityId = $this->argument('activityId');
$this->info("Searching for activity with: {$activityId}");
if (is_numeric($activityId)) {
$activity = Activity::find((int) $activityId);
} else {
$activity = Activity::where('uuid', \Jiminny\Traits\RequiresUUID::toOptimized($activityId))->first();
}
if (! $activity) {
$this->error("Activity with ID/UUID {$activityId} not found");
return;
}
$this->info("Found activity ID: {$activity->getId()}, UUID: {$activity->getUuid()}");
$this->info('Sending activity for ES update...');
try {
$this->eventDispatcher->dispatch(
new UpdateSingleEntity(
entityId: $activity->getId(),
updateTarget: UpdateTargetEnum::ACTIVITY,
purpose: 'cli-command-activity-update-es',
isSyncEvent: true,
)
);
$this->info('Done.');
} catch (\Exception $e) {
$this->error('Failed to update ES: ' . $e->getMessage());
$this->error($e->getTraceAsString());
}
}
}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20903-update_activity-stage-on-opportunity-change, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.12932181,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20903-update_activity-stage-on-opportunity-change","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8081782,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AskJiminnyReportActivityServiceTest","depth":6,"bounds":{"left":0.8234708,"top":0.019952115,"width":0.09208777,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AskJiminnyReportActivityServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7","depth":4,"bounds":{"left":0.38430852,"top":0.22426178,"width":0.0076462766,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.39361703,"top":0.22266561,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.40093085,"top":0.22266561,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Contracts\\Events\\Dispatcher;\nuse Jiminny\\Contracts\\ES\\Events\\UpdateSingleEntity;\nuse Jiminny\\Contracts\\ES\\UpdateTargetEnum;\nuse Jiminny\\Models\\Activity;\n\nclass UpdateActivityElasticSearchDocumentCommand extends Command\n{\n protected $signature = 'activity:update:es {activityId}';\n protected $description = 'Update ES document synchronously';\n\n public function __construct(private readonly Dispatcher $eventDispatcher)\n {\n parent::__construct();\n }\n\n public function handle(): void\n {\n $activityId = $this->argument('activityId');\n\n $this->info(\"Searching for activity with: {$activityId}\");\n\n if (is_numeric($activityId)) {\n $activity = Activity::find((int) $activityId);\n } else {\n $activity = Activity::where('uuid', \\Jiminny\\Traits\\RequiresUUID::toOptimized($activityId))->first();\n }\n\n if (! $activity) {\n $this->error(\"Activity with ID/UUID {$activityId} not found\");\n\n return;\n }\n\n $this->info(\"Found activity ID: {$activity->getId()}, UUID: {$activity->getUuid()}\");\n $this->info('Sending activity for ES update...');\n\n try {\n $this->eventDispatcher->dispatch(\n new UpdateSingleEntity(\n entityId: $activity->getId(),\n updateTarget: UpdateTargetEnum::ACTIVITY,\n purpose: 'cli-command-activity-update-es',\n isSyncEvent: true,\n )\n );\n\n $this->info('Done.');\n } catch (\\Exception $e) {\n $this->error('Failed to update ES: ' . $e->getMessage());\n $this->error($e->getTraceAsString());\n }\n }\n}","depth":4,"bounds":{"left":0.15924202,"top":0.22106944,"width":0.31981382,"height":0.77893054},"on_screen":true,"value":"<?php\n\nnamespace Jiminny\\Console\\Commands\\Activities;\n\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Contracts\\Events\\Dispatcher;\nuse Jiminny\\Contracts\\ES\\Events\\UpdateSingleEntity;\nuse Jiminny\\Contracts\\ES\\UpdateTargetEnum;\nuse Jiminny\\Models\\Activity;\n\nclass UpdateActivityElasticSearchDocumentCommand extends Command\n{\n protected $signature = 'activity:update:es {activityId}';\n protected $description = 'Update ES document synchronously';\n\n public function __construct(private readonly Dispatcher $eventDispatcher)\n {\n parent::__construct();\n }\n\n public function handle(): void\n {\n $activityId = $this->argument('activityId');\n\n $this->info(\"Searching for activity with: {$activityId}\");\n\n if (is_numeric($activityId)) {\n $activity = Activity::find((int) $activityId);\n } else {\n $activity = Activity::where('uuid', \\Jiminny\\Traits\\RequiresUUID::toOptimized($activityId))->first();\n }\n\n if (! $activity) {\n $this->error(\"Activity with ID/UUID {$activityId} not found\");\n\n return;\n }\n\n $this->info(\"Found activity ID: {$activity->getId()}, UUID: {$activity->getUuid()}\");\n $this->info('Sending activity for ES update...');\n\n try {\n $this->eventDispatcher->dispatch(\n new UpdateSingleEntity(\n entityId: $activity->getId(),\n updateTarget: UpdateTargetEnum::ACTIVITY,\n purpose: 'cli-command-activity-update-es',\n isSyncEvent: true,\n )\n );\n\n $this->info('Done.');\n } catch (\\Exception $e) {\n $this->error('Failed to update ES: ' . $e->getMessage());\n $this->error($e->getTraceAsString());\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-3663959127365484377
|
-3950718552507245786
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20903-update_activity- Project: faVsco.js, menu
JY-20903-update_activity-stage-on-opportunity-change, menu
Start Listening for PHP Debug Connections
AskJiminnyReportActivityServiceTest
Run 'AskJiminnyReportActivityServiceTest'
Debug 'AskJiminnyReportActivityServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
7
Previous Highlighted Error
Next Highlighted Error
<?php
namespace Jiminny\Console\Commands\Activities;
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
use Jiminny\Contracts\ES\Events\UpdateSingleEntity;
use Jiminny\Contracts\ES\UpdateTargetEnum;
use Jiminny\Models\Activity;
class UpdateActivityElasticSearchDocumentCommand extends Command
{
protected $signature = 'activity:update:es {activityId}';
protected $description = 'Update ES document synchronously';
public function __construct(private readonly Dispatcher $eventDispatcher)
{
parent::__construct();
}
public function handle(): void
{
$activityId = $this->argument('activityId');
$this->info("Searching for activity with: {$activityId}");
if (is_numeric($activityId)) {
$activity = Activity::find((int) $activityId);
} else {
$activity = Activity::where('uuid', \Jiminny\Traits\RequiresUUID::toOptimized($activityId))->first();
}
if (! $activity) {
$this->error("Activity with ID/UUID {$activityId} not found");
return;
}
$this->info("Found activity ID: {$activity->getId()}, UUID: {$activity->getUuid()}");
$this->info('Sending activity for ES update...');
try {
$this->eventDispatcher->dispatch(
new UpdateSingleEntity(
entityId: $activity->getId(),
updateTarget: UpdateTargetEnum::ACTIVITY,
purpose: 'cli-command-activity-update-es',
isSyncEvent: true,
)
);
$this->info('Done.');
} catch (\Exception $e) {
$this->error('Failed to update ES: ' . $e->getMessage());
$this->error($e->getTraceAsString());
}
}
}...
|
40901
|
NULL
|
NULL
|
NULL
|