Skip to content

Instantly share code, notes, and snippets.

@whoisdevd
Last active June 6, 2024 15:30
Show Gist options
  • Save whoisdevd/a9dc3bdb9cee9f69a03981a0143d390a to your computer and use it in GitHub Desktop.
Save whoisdevd/a9dc3bdb9cee9f69a03981a0143d390a to your computer and use it in GitHub Desktop.
PASS Migration Snippets
<?php
# PASS Migration Snippets
$migrations = PassPlusMigration::where('status', 'UploadingOnHold')->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_READY)->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_RESTORING)->get();
foreach ($migrations as $migration) { CheckRestoreStatus::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); MakeClassicEventItemsPublic::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); }
foreach ($migrations as $migration) { CheckRestoreStatus::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); }
foreach ($migrations as $i => $migration) { echo $i . PHP_EOL; MakeClassicEventItemsPublic::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); }
$migrations = PassPlusMigration::whereBetween('id', [171, 186])->get();
foreach ($migrations as $migration) { CheckRestoreStatus::dispatchNow($migration); }
foreach ($migrations as $i => $migration) { RestoreClassicEventItemsInBatch::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); echo $i . "\n"; }
foreach ($migrations as $i => $migration) { CheckRestoreStatus::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); echo $i . "\n"; }
foreach ($migrations as $i => $migration) { UploadClassicEventItemsToPassPlus::dispatch($migration)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); echo $i . "\n"; }
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_PREPARING)->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_READY)->get();
$migrations = PassPlusMigration::where('status', 'OnHold')->get();
$migrations = PassPlusMigration::where('status', 'OnHold')->update(['status' => PassPlusMigration::STATUS_READY]);
foreach ($migrations as $i => $migration) { PreparePassPlusMigrationData::dispatch($migration, true)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); echo $i . "\n"; }
foreach ($migrations as $i => $migration) { PreparePassPlusMigrationData::dispatchNow($migration, null, true, true); echo $i . "\n"; }
// Find galleries by event_id
$events = collect($migration->events)->filter(function($e) { return $e->event_id == 114407; })->toArray();
// Find galleries by status
$events = collect($migration->events)->filter(function($e) { return $e->status != 'Downloaded'; })->toArray();
$events = collect($migration->events)->filter(function($e) { return $e->status == 'Finished'; })->toArray();
$events = collect($migration->events)->filter(function($e) { return $e->status == 'Upload Queued'; })->toArray();
// Find/get a migration
$migration = PassPlusMigration::find(1806);
// Run jobs for the whole migration
PreparePassPlusMigrationData::dispatchNow($migration);
RestoreClassicEventItemsInBatch::dispatchNow($migration);
MakeClassicEventItemsPublic::dispatchNow($migration);
CheckRestoreStatus::dispatchNow($migration);
DownloadGalleryOnWindows::dispatchNow($migration);
CheckDownloadStatus::dispatchNow($migration);
UploadClassicEventItemsToPassPlus::dispatchNow($migration);
CheckUploadStatusOfClassicEventItems::dispatchNow($migration);
// Run jobs for migration with specific events/galleries
PreparePassPlusMigrationData::dispatchNow($migration, null, true, true);
RestoreClassicEventItemsInBatch::dispatchNow($migration, $events);
MakeClassicEventItemsPublic::dispatchNow($migration, $events);
CheckRestoreStatus::dispatchNow($migration, null, true, true);
CheckRestoreStatus::dispatchNow($migration, $events);
DownloadGalleryOnWindows::dispatchNow($migration, $events);
CheckDownloadStatus::dispatchNow($migration, null, true, true);
CheckDownloadStatus::dispatchNow($migration, $events);
UploadClassicEventItemsToPassPlus::dispatchNow($migration, $events);
CheckUploadStatusOfClassicEventItems::dispatchNow($migration, $events);
CheckUploadStatusOfClassicEventItems::dispatchNow($migration, null, true, true);
$migration->photos()->where('pass_classic_event_id', 2232712)->distinct('pass_classic_event_item_id')->count()
DownloadGalleryOnWindows::dispatchNow($migration, $events);
DownloadGalleryOnWindows::dispatchNow($migration, null, true, true);
// 1362648, 1480482, 1487251, 2158704, 2134812, :2081481, :2053743
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_RESTORING)->whereBetween('id', [300, 334])->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_ERROR)->whereBetween('id', [285, 321])->get();
PassPlusMigration::where('status', PassPlusMigration::STATUS_DOWNLOADED)->update(['instance_id' => 4])
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_DOWNLOADED)->get();
$migrations = PassPlusMigration::whereInstanceId(1)->where('status', PassPlusMigration::STATUS_RESTORING)->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_DOWNLOADING)->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_UPLOADING)->get();
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_RESTORED)->get()
$migrations = PassPlusMigration::where('status', PassPlusMigration::STATUS_ERROR)->get();
foreach ($migrations as $migration) { MakeClassicEventItemsPublic::dispatchNow($migration); }
foreach ($migrations as $migration) { RestoreClassicEventItemsInBatch::dispatchNow($migration); }
foreach ($migrations as $migration) { CheckRestoreStatus::dispatchNow($migration); }
foreach ($migrations as $migration) { DownloadGalleryOnWindows::dispatchNow($migration); }
foreach ($migrations as $migration) { CheckDownloadStatus::dispatchNow($migration); }
foreach ($migrations as $migration) { CheckUploadStatusOfClassicEventItems::dispatchNow($migration); }
foreach ($migrations as $migration) { UploadClassicEventItemsToPassPlus::dispatchNow($migration); }
$job->getUserEvents($migration->pass_classic_user_id);
$classicUserId = $migration->pass_classic_user_id;
$passClassicDB->table('event')->where('owner_id', '=', $classicUserId)->where('deleted', '=', 0)->where('num_items', '!=', 0)->count();
$passClassicDB->table('event')->where('owner_id', '=', $classicUserId)->count();
/*
[2023-09-05 11:46:11] production.ERROR: Error sending upload request to PASS+ {"event":2330109,"error":"Client error: `POST https://productionapi.pic-time.com/apiV2/automation/checkin?accountId=202255` resulted in a `404 Not Found` response:
{\"Message\":\"No HTTP resource was found that matches the request URI 'https://productionapi.pic-time.com/apiV2/automation (truncated...)
"}
[2023-09-05 11:46:11] production.ERROR: Error sending upload request to PASS+ {"event":2330109,"error":"Client error: `POST https://productionapi.pic-time.com/apiV2/automation/checkin?accountId=202255` resulted in a `404 Not Found` response:
{\"Message\":\"No HTTP resource was found that matches the request URI 'https://productionapi.pic-time.com/apiV2/automation (truncated...)
"}
[2023-09-05 11:46:13] production.DEBUG: Middleware stack {"headers":{"Authorization":["Bearer AAAAAGIAAADXV9EwIvACpeDHw9QFw-QVPCLIu1n2wHNUkuseD8M0ko7SKx1g3yrKECEqzu8Pdh3U1vsw2yYAHuVQGRUvuQfY"],"Accept":["application/json"],"User-Agent":["GuzzleHttp/6.5.5 curl/7.74.0 PHP/7.3.33"],"Host":["productionapi.pic-time.com"],"Content-Type":["application/json"]},"body":""}
[2023-09-05 11:46:13] production.DEBUG: Middleware stack {"headers":{"Authorization":["Bearer AAAAAGIAAADXV9EwIvACpeDHw9QFw-QVPCLIu1n2wHNUkuseD8M0ko7SKx1g3yrKECEqzu8Pdh3U1vsw2yYAHuVQGRUvuQfY"],"Accept":["application/json"],"User-Agent":["GuzzleHttp/6.5.5 curl/7.74.0 PHP/7.3.33"],"Host":["productionapi.pic-time.com"],"Content-Type":["application/json"]},"body":""}
[2023-09-05 11:46:13] production.DEBUG: Pass getCampaignTemplateProjectId {"status":200,"templateProjectId":32147541,"response-body":"[object] (Guz
*/
$httpClient = new GuzzleHttp\Client;
$migrations = PassPlusMigration::where('status', 'Restored')->get();
$migrations = PassPlusMigration::whereIn('id', [398,411,531,533,592,763,770,878,891,896,897,930,937,945,952,976,981,1070,1081,1119,1126, 890, 524,899,902])->get();
foreach ($migrations as $i => $migration) {
$photos = $migration->photos()->inRandomOrder()->limit(500)->get();
$isArchived = false;
foreach ($photos as $photo) {
try {
$response = $httpClient->get($photo->url);
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
Log::error('Error downloading photo', ['migration' => $migration->id, 'photo' => $photo->id, 'error' => $e->getMessage()]);
if ($e->getResponse()->getStatusCode() == 403) {
$isArchived = true;
break;
}
}
}
if ($isArchived) {
RestoreClassicEventItemsInBatch::dispatchNow($migration);
}
echo $i . PHP_EOL;
}
$httpClient = new GuzzleHttp\Client; $migrations = PassPlusMigration::where('status', 'Restoring')->get(); foreach ($migrations as $i => $migration) { $photos = $migration->photos()->inRandomOrder()->limit(200)->get(); $isArchived = false; foreach ($photos as $photo) { try { $response = $httpClient->get($photo->url); } catch (\GuzzleHttp\Exception\BadResponseException $e) { Log::error('Error downloading photo', ['migration' => $migration->id, 'photo' => $photo->id, 'error' => $e->getMessage()]); if ($e->getResponse()->getStatusCode() == 403) { $isArchived = true; break; } } } if ($isArchived) { RestoreClassicEventItemsInBatch::dispatchNow($migration, null, true, true); } echo $i . PHP_EOL; }
$migrations = PassPlusMigration::whereNotNull('downloaded_at')->get();
foreach ($migrations as $i => $migration) { MakeClassicEventItemsPublic::dispatchNow($migration); echo $i . PHP_EOL; }
foreach ($migrations as $i => $migration) { CheckDownloadStatus::dispatchNow($migration, null, true, true); echo $i . PHP_EOL; }
foreach ($migrations as $i => $migration) { RestoreClassicEventItemsInBatch::dispatchNow($migration, null, true, true); echo $i . PHP_EOL; }
foreach ($migrations as $i => $migration) { CheckRestoreStatus::dispatchNow($migration, null, true, true); echo $i . PHP_EOL; }
foreach ($migrations as $i => $migration) { CheckRestoreStatus::dispatchNow($migration); echo $i . PHP_EOL; }
CheckDownloadStatus::dispatchNow($migration)
$migrations = PassPlusMigration::where('status', 'Restored')->get();
foreach ($migrations as $i => $migration) { CheckRestoreStatus::dispatch($migration, $selectedEvents)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); echo $i . PHP_EOL; }
$migrations = PassPlusMigration::with(['galleries' => function($q) { $q->withCount('photos'); } ])->where('status', 'Restoring')->get();
$ids = [];
foreach ($migrations as $i => $migration) {
$galleries = $migration->galleries()->select(['id', 'pass_plus_migration_id', 'status', 'plass_classic_event_id'])->withCount('photos')->get();
foreach ($galleries as $gallery) {
if ($gallery->photos_count == 0) {
$gallery->delete();
$ids[] = $gallery->id;
echo $migration->id . ' - ' . $gallery->id . PHP_EOL;
}
}
}
$migrations = PassPlusMigration::where('status', 'Restoring')->whereIn('instance_id', [1, 2, 4, 10])->select(['id', 'status', 'instance_id'])->get();
$migrations = PassPlusMigration::where('status', 'Restoring')->whereIn('instance_id', [1])->select(['id', 'status', 'instance_id'])->get();
$migrations = PassPlusMigration::where('status', 'Restoring')->whereIn('instance_id', [2])->select(['id', 'status', 'instance_id'])->get();
$migrations = PassPlusMigration::where('status', 'Restoring')->whereIn('instance_id', [11])->select(['id', 'status', 'instance_id'])->get();
$migrations = PassPlusMigration::where('status', 'Restoring')->whereIn('instance_id', [4,8, 10, 11])->select(['id', 'status', 'instance_id'])->get();
$migrations = PassPlusMigration::where('status', 'Uploading')->select(['id', 'status', 'instance_id'])->get();
foreach ($migrations as $i => $migration) {
$migration->galleries()->update(['status' => 'Restoring', 'restored_at' => null]);
$migration->photos()->update(['status' => 'Restoring', 'restored_at' => null, 'expires_at' => null]);
CheckRestoreStatus::dispatch($migration, null, true, true)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration'));
echo $i . ' - ' . $migration->id . PHP_EOL;
}
foreach ($migrations as $i => $migration) { $migration->galleries()->update(['status' => 'Restoring', 'restored_at' => null]); $migration->photos()->update(['status' => 'Restoring', 'restored_at' => null, 'expires_at' => null]); CheckRestoreStatus::dispatch($migration, null, true, true)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); echo $i . ' - ' . $migration->id . PHP_EOL; }
$migrations = PassPlusMigration::where('status', 'Restoring')->get()->pluck('id')->toArray();
PassPlusMigrationPhoto::whereIn('migration_id', $migrations)->update(['status' => 'Restoring', 'restored_at' => null, 'restored_by' => null, 'restored_from' => null, 'restored_to' => null, 'restored_error' => null, 'restored_error_message' => null, 'restored_error_details' => null, 'restored_error_code' => null, 'restored_error_file' => null, 'restored_error_line' => null, 'restored_error_trace' => null, 'restored_error_previous' => null, 'restored_error_trace_s']);
YKv3T1561920/GLN9j266968028x.jpg
$galleries = $migrations->first()->galleries()->select(['id', 'pass_plus_migration_id', 'status', 'pass_classic_event_id'])->withCount('photos')->get();
[262966,648689,1285223,2743597,1090798,901605,3633517,297865,3373123,1927938,3836009,3768249,188963,100358,3564780,3020518,2530235,2409819,2745587,1840357,3060110,1728831,1764675,100638,4101894,830638,2189997,2666369,2917769,482348,356493,2030909,986259,1199471]
[262966,648689,1285223,2743597,1090798,901605,3633517,297865,3373123,1927938,3836009,3768249,188963,100358,3564780,3020518,2530235,2409819,2745587,1840357,3060110,1728831,1764675,100638,4101894,830638,2189997,2666369,2917769,482348,356493,2030909,986259,1199471]
$events = collect($migration->events)->filter(function($e) { return $e->status == 'Uploading'; })->toArray();
$s3Client = AWS::createClient('s3'); $classicEventBucket = env('CLASSIC_EVENT_BUCKET', 'data.passpremier.com');
$result = $s3Client->putObjectAcl(['Bucket' => $classicEventBucket, 'Key' => $key, 'ACL' => 'public-read']);
$migration = PassPlusMigration::find(1172);
$key = $migration->photos()->first()->s3_image_path;
$status = $s3Client->headObject(['Bucket' => $classicEventBucket, 'Key' => $key]);
$restoreFlag = $status->getPath('Restore');
$storageClass = $status->getPath('StorageClass');
$needle = 'expiry-date=';
$str = substr($restoreFlag, strpos($restoreFlag, $needle) + strlen($needle));
// $expiryDate = str_replace('"', '', substr($restoreFlag, strpos($restoreFlag, $needle) + strlen($needle)));
$expiryDate = str_replace('"', '', explode('expiry-date=', $restoreFlag)[1]);
$expiresAt = date('Y-m-d H:i:s', strtotime($expiryDate));
'expires_at' => $expiresAt,
$expiryDate = str_replace('"', '', explode('expiry-date=', $restoreFlag)[1]);
$expiresAt = date('Y-m-d H:i:s', strtotime($expiryDate));
Log::info("Restored $key. Expires at $expiresAt");
return 'Restored|' . $expiresAt;
$expiresAt = explode('|', $status)[1];
$galleryService = new CreatePassGalleryService($migration->pass_plus_account_id);
foreach ($migration->galleries as $i => $gallery) {
if (! isset($gallery->pass_plus_upload_status['projectId'])) {
continue;
}
$galleryService->cancelIncompleteUploads($gallery->pass_plus_upload_status['projectId']);
echo $i . PHP_EOL;
}
/* Terraform command
master-df9f827a8
aws ecs execute-command --cluster <CLUSTER_NAME> --command bash --interactive --task <TASK_NAME>
terraform taint aws_ecs_task_definition.app
terraform taint aws_ecs_task_definition.worker
terraform taint module.event-validation.aws_ecs_task_definition.definition
terraform taint module.restore-images-for-migration.aws_ecs_task_definition.definition
terraform taint module.restore-images-for-migration.aws_cloudwatch_log_group.cloudwatch_log_group
terraform taint module.event-validation.aws_cloudwatch_log_group.cloudwatch_log_group
terraform taint module.restore-images.aws_cloudwatch_log_group.cloudwatch_log_group
aws_lb_target_group
*/
PROD ASSIGN: https://productionapi.pic-time.com/apiV2/autoAppCreateAndAssign
{
"accountId": "155967",
"campaigns": {
"strategyUniqueId": 500012,
"campaignId": null,
"customSetups": null
},
"projectfiltering": {
"fromYear": null,
"toYear": null,
"categories": null,
"onlyOnline": null,
"externalSystem":"passmigration"
}
}
aws s3control list-jobs --profile vivi-deploy --region us-east-1 --account-id 958681535937 --job-statuses 'Ready' 'Preparing' 'Running'
aws s3control list-jobs --profile vivi-deploy --region us-east-1 --account-id 958681535937 --job-statuses 'Running'
$migration = PassPlusMigration::find(755);
$events = $migration->events;
foreach ($migration->galleries as $gallery) {
if (empty($gallery->pass_plus_storage_status)) {
continue;
}
$storageStatus = $gallery->pass_plus_storage_status;
$uniquePhotos = $migration->photos()->where('pass_classic_event_id', $gallery->pass_classic_event_id)->distinct('pass_classic_event_item_id')->count();
$cutOffPhotos = intval($uniquePhotos * 0.98);
if ($storageStatus['storageCount'] > 0 && $storageStatus['storageCount'] >= $cutOffPhotos) {
Log::info('Gallery ' . $gallery->id . ' has ' . $storageStatus['storageCount'] . ' photos out of ' . $uniquePhotos . ' photos in storage');
// $gallery->update(['status' => 'Finished', completed_at => now()]);
}
}
$expiresAt = $migration->images_expires_at;
if (now()->diffInDays($expiresAt) < 1) {
RestoreClassicEventItemsInBatch::dispatch($migration)
->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration'));
return 'Dispatched restoration job';
}
if ($this->hasActiveDownload($migration)) {
return 'Download already in progress';
}
{
"revisionCount": {
"0": 153
},
"ok": true,
"errorMessage": null
}
PassPlusMigration::where('email', ' [email protected] ')->orWhere('pass_plus_account_id', 72912)->first();
$migrations = PassPlusMigration::where('status', 'Uploading')->select(['id', 'status', 'instance_id', 'pass_plus_account_id'])->get();
foreach ($migrations as $i => $migration) {
echo 'Processing Migration: ' . $migration->id . PHP_EOL;
$events = collect($migration->events)->filter(function($e) { return $e->status == 'Upload Queued'; })->toArray();
echo 'Pending Galleries: ' . count($events) . PHP_EOL;
$chunks = array_chunk($events, 10);
foreach($chunks as $chunk) {
UploadClassicEventItemsToPassPlus::dispatch($migration, $chunk, true, true)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration'));
}
echo 'Total Migration Processed: ' . ($i+1) . PHP_EOL;
}
$migrations = PassPlusMigration::where('status', 'Uploading')->select(['id', 'status', 'instance_id', 'pass_plus_account_id'])->get(); foreach ($migrations as $i => $migration) { echo 'Processing Migration: ' . $migration->id . PHP_EOL; $events = collect($migration->events)->filter(function($e) { return $e->status == 'Upload Queued'; })->toArray(); echo 'Pending Galleries: ' . count($events) . PHP_EOL; $chunks = array_chunk($events, 10); foreach($chunks as $chunk) { UploadClassicEventItemsToPassPlus::dispatch($migration, $chunk, true, true)->onConnection(env('SQS_RESTORE_IMAGES_CONNECTION', 'sqs-restore-images-for-migration')); } echo 'Total Migration Processed: ' . ($i+1) . PHP_EOL; }
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project projectRef="2602-1251769">
<product imageGuid="221805839" requestGuid="615014493"/>
</project>
$migrations = PassPlusMigration::where('status', 'Error')->select(['id', 'status', 'instance_id', 'pass_plus_account_id', 'pass_classic_user_id', 'type'])->latest()->get();
foreach ($migrations as $i => $migration) {
echo 'Processing Migration: ' . $migration->id . PHP_EOL;
$events = collect($migration->events)->filter(function($e) { return $e->status == 'Upload Queued'; })->toArray();
if (count($events) == 0) {
continue;
}
$eventIds = collect($events)->pluck('event_id')->toArray();
echo 'Pending Galleries: ' . count($eventIds) . PHP_EOL;
$prepare = array_fill_keys($eventIds, null);
PreparePassPlusMigrationData::dispatchNow($migration, $prepare, true, true);
CheckUploadStatusOfClassicEventItems::dispatchNow($migration, $events);
echo 'Total Migration Processed: ' . ($i+1) . PHP_EOL;
}
PreparePassPlusMigrationData::dispatchNow($migration, $prepare, false, false);
CheckUploadStatusOfClassicEventItems::dispatchNow($migration, $events);
<!-- UploadClassicEventItemsToPassPlus::dispatchNow($migration, $events, true, true); -->
foreach ($migrations as $i => $migration) {
echo 'Processing Migration: ' . $migration->id . PHP_EOL;
PreparePassPlusMigrationData::dispatchNow($migration, null, true, true);
$migration->update(['status' => 'Uploading']);
echo 'Total Migration Processed: ' . ($i+1) . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment