examples/AdWords/v201809/Migration/MigrateToExtensionSettings.php
private static function createExtensionSetting(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $sitelinksFromFeed,
        $campaignId,
        array $feedItemIds,
        $platformRestrictions
    ) {
        $campaignExtensionSettingService = $adWordsServices->get($session, CampaignExtensionSettingService::class);

        $extensionSetting = new CampaignExtensionSetting();
        $extensionSetting->setCampaignId($campaignId);
        $extensionSetting->setExtensionType(FeedType::SITELINK);
        $extensionSetting->setExtensionSetting(new ExtensionSetting());

        $extensionFeedItems = [];
        foreach ($feedItemIds as $feedItemId) {
            $sitelink = $sitelinksFromFeed[$feedItemId];

            $newFeedItem = new SitelinkFeedItem();
            $newFeedItem->setSitelinkText($sitelink->getText());
            $newFeedItem->setSitelinkUrl($sitelink->getUrl());
            $newFeedItem->setSitelinkLine2($sitelink->getLine2());
            $newFeedItem->setSitelinkLine3($sitelink->getLine3());
            $newFeedItem->setSitelinkFinalUrls($sitelink->getFinalUrls());
            $newFeedItem->setSitelinkFinalMobileUrls($sitelink->getFinalMobileUrls());
            $newFeedItem->setSitelinkTrackingUrlTemplate(
                $sitelink->getTrackingUrlTemplate()
            );

            $extensionFeedItems[] = $newFeedItem;
        }
        $extensionSetting->getExtensionSetting()->setExtensions(
            $extensionFeedItems
        );
        $extensionSetting->getExtensionSetting()->setPlatformRestrictions(
            $platformRestrictions
        );

        $operation = new CampaignExtensionSettingOperation();
        $operation->setOperand($extensionSetting);
        $operation->setOperator(Operator::ADD);

        printf(
            "Adding %d sitelinks for campaign ID %d...\n",
            count($feedItemIds),
            $campaignId
        );

        return $campaignExtensionSettingService->mutate([$operation]);
    }
private static function createExtensionSetting(
        AdWordsServices $adWordsServices,
        AdWordsSession $session,
        array $sitelinksFromFeed,
        $campaignId,
        array $feedItemIds,
        $platformRestrictions
    ) {
        $campaignExtensionSettingService = $adWordsServices->get($session, CampaignExtensionSettingService::class);

        $extensionSetting = new CampaignExtensionSetting();
        $extensionSetting->setCampaignId($campaignId);
        $extensionSetting->setExtensionType(FeedType::SITELINK);
        $extensionSetting->setExtensionSetting(new ExtensionSetting());

        $extensionFeedItems = [];
        foreach ($feedItemIds as $feedItemId) {
            $sitelink = $sitelinksFromFeed[$feedItemId];

            $newFeedItem = new SitelinkFeedItem();
            $newFeedItem->setSitelinkText($sitelink->getText());
            $newFeedItem->setSitelinkUrl($sitelink->getUrl());
            $newFeedItem->setSitelinkLine2($sitelink->getLine2());
            $newFeedItem->setSitelinkLine3($sitelink->getLine3());
            $newFeedItem->setSitelinkFinalUrls($sitelink->getFinalUrls());
            $newFeedItem->setSitelinkFinalMobileUrls($sitelink->getFinalMobileUrls());
            $newFeedItem->setSitelinkTrackingUrlTemplate(
                $sitelink->getTrackingUrlTemplate()
            );

            $extensionFeedItems[] = $newFeedItem;
        }
        $extensionSetting->getExtensionSetting()->setExtensions(
            $extensionFeedItems
        );
        $extensionSetting->getExtensionSetting()->setPlatformRestrictions(
            $platformRestrictions
        );

        $operation = new CampaignExtensionSettingOperation();
        $operation->setOperand($extensionSetting);
        $operation->setOperator(Operator::ADD);

        printf(
            "Adding %d sitelinks for campaign ID %d...\n",
            count($feedItemIds),
            $campaignId
        );

        return $campaignExtensionSettingService->mutate([$operation]);
    }
private static function createExtensionSetting ( AdWordsServices $ adWordsServices , AdWordsSession $ session , array $ sitelinksFromFeed , $ campaignId , array $ feedItemIds , $ platformRestrictions ) { $ campaignExtensionSettingService = $ adWordsServices -> get ( $ session , CampaignExtensionSettingService :: class ) ; $ extensionSetting = new CampaignExtensionSetting ( ) ; $ extensionSetting -> setCampaignId ( $ campaignId ) ; $ extensionSetting -> setExtensionType ( FeedType :: SITELINK ) ; $ extensionSetting -> setExtensionSetting ( new ExtensionSetting ( ) ) ; $ extensionFeedItems = [ ] ; foreach ( $ feedItemIds as $ feedItemId ) { $ sitelink = $ sitelinksFromFeed [ $ feedItemId ] ; $ newFeedItem = new SitelinkFeedItem ( ) ; $ newFeedItem -> setSitelinkText ( $ sitelink -> getText ( ) ) ; $ newFeedItem -> setSitelinkUrl ( $ sitelink -> getUrl ( ) ) ; $ newFeedItem -> setSitelinkLine2 ( $ sitelink -> getLine2 ( ) ) ; $ newFeedItem -> setSitelinkLine3 ( $ sitelink -> getLine3 ( ) ) ; $ newFeedItem -> setSitelinkFinalUrls ( $ sitelink -> getFinalUrls ( ) ) ; $ newFeedItem -> setSitelinkFinalMobileUrls ( $ sitelink -> getFinalMobileUrls ( ) ) ; $ newFeedItem -> setSitelinkTrackingUrlTemplate ( $ sitelink -> getTrackingUrlTemplate ( ) ) ; $ extensionFeedItems [ ] = $ newFeedItem ; } $ extensionSetting -> getExtensionSetting ( ) -> setExtensions ( $ extensionFeedItems ) ; $ extensionSetting -> getExtensionSetting ( ) -> setPlatformRestrictions ( $ platformRestrictions ) ; $ operation = new CampaignExtensionSettingOperation ( ) ; $ operation -> setOperand ( $ extensionSetting ) ; $ operation -> setOperator ( Operator :: ADD ) ; printf ( "Adding %d sitelinks for campaign ID %d...\n" , count ( $ feedItemIds ) , $ campaignId ) ; return $ campaignExtensionSettingService -> mutate ( [ $ operation ] ) ; }
Creates a new extension setting for the specified feed items.
Creates a new extension setting for the specified feed items .