Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmenich committed Oct 8, 2024
2 parents b1de1ee + 0e52798 commit 00387dd
Showing 1 changed file with 39 additions and 45 deletions.
84 changes: 39 additions & 45 deletions src/jobs/ShowEntriesSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ public function execute( $queue ): void
$existingEntry = $this->findExistingShowEntry( $showEntry->data->id );
$isNew = !$existingEntry;
$entry = $this->chooseOrCreateShowEntry( $showAttributes->title, $existingEntry );

$showImages = $showAttributes->images;
$showImagesKeywords = ['mezzanine', 'poster', 'white', 'black', 'color'];
$showImageArray = [];

if(isset($showImages) && is_array($showImages)) {
foreach( $showAttributes->images as $image ) {

foreach($showImagesKeywords as $keyword){
if(str_contains($image->profile, $keyword)) {

$asset = $this->createOrUpdateImage( $showAttributes->title, $image, $image->profile);
if( $asset && isset( $asset->id ) ) {
$showImageArray[$keyword] = $asset->id;
}
}
}

}
}

Expand All @@ -121,7 +121,7 @@ public function execute( $queue ): void

// Set field values based on API Column Fields on settings
$apiColumnFields = SettingsHelper::get( 'showApiColumnFields' );

foreach( $apiColumnFields as $apiColumnField ) {

$apiField = $apiColumnField[ 0 ];
Expand All @@ -147,7 +147,7 @@ public function execute( $queue ): void
}
$episodeAssetsUrl = $episodesData[0]->links->assets;
$episodeAssets = $this->fetchShowEntry($episodeAssetsUrl);

if(!$episodeAssets) {
break;
}
Expand Down Expand Up @@ -197,45 +197,45 @@ public function execute( $queue ): void
}

break;

case 'show_mezzanine':
$fieldHandle = SynchronizeHelper::getApiField('show_mezzanine', 'showApiColumnFields');

if( isset($showImageArray['mezzanine']) ) {
$defaultFields[$fieldHandle] = [$showImageArray['mezzanine']];
}
break;

case 'show_poster':
$fieldHandle = SynchronizeHelper::getApiField('show_poster', 'showApiColumnFields');
if( isset($showImageArray['poster']) ) {
$defaultFields[$fieldHandle] = [$showImageArray['poster']];
}
break;

case 'show_white_logo':
$fieldHandle = SynchronizeHelper::getApiField('show_white_logo', 'showApiColumnFields');

if( isset($showImageArray['white']) ) {
$defaultFields[$fieldHandle] = [$showImageArray['white']];
}
break;

case 'show_black_logo':
$fieldHandle = SynchronizeHelper::getApiField('show_black_logo', 'showApiColumnFields');
if( isset($showImageArray['black']) ) {
$defaultFields[$fieldHandle] = [$showImageArray['black']];
}
break;

case 'show_color_logo':
$fieldHandle = SynchronizeHelper::getApiField('show_color_logo', 'showApiColumnFields');

if( isset($showImageArray['color']) ) {
$defaultFields[$fieldHandle] = [$showImageArray['color']];
}
break;

case 'show_address':
if( isset( $showAttributes->slug ) ) {
$defaultFields[ SynchronizeHelper::getApiField( $apiField, 'showApiColumnFields' ) ] = 'https://pbs.org/show/' . $showAttributes->slug;
Expand Down Expand Up @@ -272,65 +272,59 @@ public function execute( $queue ): void
}
break;
case 'description_long':
// Only if new entry add description
if( !$existingEntry ) {
$defaultFields[ SynchronizeHelper::getApiField( $apiField, 'showApiColumnFields' ) ] = $showAttributes->description_long;
}
$defaultFields[ SynchronizeHelper::getApiField( $apiField, 'showApiColumnFields' ) ] = $showAttributes->description_long;
break;
case 'description_short':
// Only if new entry add description
if( !$existingEntry ) {
$defaultFields[ SynchronizeHelper::getApiField( $apiField, 'showApiColumnFields' ) ] = $showAttributes->description_short;
}
$defaultFields[ SynchronizeHelper::getApiField( $apiField, 'showApiColumnFields' ) ] = $showAttributes->description_short;
break;

case 'links':

if(isset($showAttributes->links) && is_array($showAttributes->links)) {

$createTable = [];
$count = 0;

foreach($showAttributes->links as $link) {
$createTable[$count]['col1'] = $link->value;
$createTable[$count]['col2'] = $link->profile;
$createTable[$count]['col3'] = new \DateTime( $link->updated_at );
$count++;
}

$defaultFields[SynchronizeHelper::getApiField($apiField, 'showApiColumnFields')] = $createTable;

}

break;

case 'platform_availability':

if(isset($showAttributes->platforms) && is_array($showAttributes->platforms)) {

$createTable = [];
$count = 0;

foreach($showAttributes->platforms as $platform) {
$createTable[$count]['col1'] = $platform->name;
$createTable[$count]['col2'] = $platform->slug;
$createTable[$count]['col3'] = new \DateTime( $platform->updated_at );
$count++;
}

$defaultFields[SynchronizeHelper::getApiField($apiField, 'showApiColumnFields')] = $createTable;
}

break;

case 'slug':

if(isset($showAttributes->slug)){
$defaultFields[SynchronizeHelper::getApiField($apiField, 'showApiColumnFields')] = $showAttributes->slug;
}

break;

case 'premiered_on':
if( $showAttributes->premiered_on != null) {
$defaultFields[ SynchronizeHelper::getApiField( $apiField, 'showApiColumnFields' ) ] = new \DateTime( $showAttributes->premiered_on );
Expand Down Expand Up @@ -544,7 +538,7 @@ private function chooseOrCreateShowEntry( $title, $entry )

if( $this->authorUsername ) {
$user = Craft::$app->users->getUserByUsernameOrEmail( $this->authorUsername );

if( $user ) {
$apiUserID = $user->id;
}
Expand Down Expand Up @@ -581,16 +575,16 @@ private function copyImageToServer( $url )
private function createOrUpdateImage($entryTitle, $imageInfo, $profile)
{
$imageUrl = $imageInfo->image;

$extension = isset(pathinfo($imageUrl)['extension']) ? pathinfo($imageUrl)['extension'] : '.jpg';
$slug = ElementHelper::normalizeSlug($entryTitle);
$filename = $slug . '-' . md5(ElementHelper::normalizeSlug($imageUrl)) . '.' . $extension;
$asset = Asset::findOne(['filename' => $filename]);

if ($asset) {
return $asset;
}

return $this->createImageAsset($imageUrl, $filename, $profile);
}

Expand Down

0 comments on commit 00387dd

Please sign in to comment.