/**
 * Updates the FeedMapping for the Feed to include AttributeFieldMappings for
 * the new line 1 and line 2 FeedAttributes.
 *
 * @param AdWordsSoapClient $feedMappingService the feed mapping service
 * @param string $feedId the feedId to attach the items to.
 * @param FeedAttribute $line1Attribute the FeedAttribute for line 1 description
 * @param FeedAttribute $line2Attribute the FeedAttribute for line 2 description
 */
function UpdateFeedMappings(AdWordsSoapClient $feedMappingService, $feedId, $line1Attribute, $line2Attribute)
{
    $selector = new Selector();
    $selector->fields = array('FeedId', 'FeedMappingId', 'PlaceholderType', 'AttributeFieldMappings');
    $selector->predicates = array();
    $selector->predicates[0] = new Predicate('FeedId', 'EQUALS', array($feedId));
    $selector->predicates[1] = new Predicate('Status', 'EQUALS', array('ACTIVE'));
    $feedMapping = $feedMappingService->get($selector)->entries[0];
    // Remove the existing mapping (FeedMapping is immutable).
    $feedMapping = $feedMappingService->mutate(array(new FeedMappingOperation($feedMapping, 'REMOVE')))->value[0];
    // Create line 1 and line 2 attribute field mappings.
    $line1FieldMapping = new AttributeFieldMapping();
    $line1FieldMapping->feedAttributeId = $line1Attribute->id;
    $line1FieldMapping->fieldId = PLACEHOLDER_FIELD_LINE_1_TEXT;
    $line2FieldMapping = new AttributeFieldMapping();
    $line2FieldMapping->feedAttributeId = $line2Attribute->id;
    $line2FieldMapping->fieldId = PLACEHOLDER_FIELD_LINE_2_TEXT;
    // Combine the existing field mappings with the new mappings.
    $feedMapping->attributeFieldMappings = array_merge($feedMapping->attributeFieldMappings, array($line1FieldMapping, $line2FieldMapping));
    $response = $feedMappingService->mutate(array(new FeedMappingOperation($feedMapping, 'ADD')));
    $mutatedMapping = $response->value[0];
    printf("Updated field mappings for feedId %d and feedMappingId %d to:\n", $mutatedMapping->feedId, $mutatedMapping->feedMappingId);
    foreach ($mutatedMapping->attributeFieldMappings as $fieldMapping) {
        printf("  feedAttributeId %s --> fieldId %s\n", $fieldMapping->feedAttributeId, $fieldMapping->fieldId);
    }
}