diff --git amazon.admin.inc amazon.admin.inc index d60a991..fd2da5d 100644 --- amazon.admin.inc +++ amazon.admin.inc @@ -87,12 +87,11 @@ function amazon_storage_settings_form($form, &$form_state) { $form['details']['amazon_core_data'] = array( '#type' => 'checkboxes', '#title' => t('Store extended product data'), - '#default_value' => variable_get('amazon_core_data', array('creators', 'images')), + '#default_value' => variable_get('amazon_core_data', array('creators', 'images', 'editorial_reviews')), '#options' => array( 'creators' => t('Book authors, film actors, etc.'), 'images' => t('Product image links'), 'editorial_reviews' => t('Editorial reviews'), - 'customer_reviews' => t('Customer reviews'), ), ); diff --git amazon.install amazon.install index 52f78d3..47e1e5b 100644 --- amazon.install +++ amazon.install @@ -78,6 +78,7 @@ function amazon_schema() { 'amazonpriceformattedprice' => array('type' => 'varchar', 'length' => 32), 'productgroup' => array('type' => 'varchar', 'length' => 255), 'producttypename' => array('type' => 'varchar', 'length' => 255), + 'customerreviews_iframe' => array('type' => 'varchar', 'length' => 255), 'invalid_asin' => array('type' => 'int', 'default' => 0), 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), ), @@ -118,17 +119,6 @@ function amazon_schema() { 'indexes' => array('asin' => array('asin')), ); - $schema['amazon_item_customer_review'] = array( - 'fields' => array( - 'asin' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), - 'rating' => array('type' => 'numeric'), - 'date' => array('type' => 'varchar', 'length' => 11), - 'summary' => array('type' => 'text'), - 'content' => array('type' => 'text'), - ), - 'indexes' => array('asin' => array('asin')), - ); - $schema['amazon_item_node'] = array( 'fields' => array( 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), @@ -160,3 +150,23 @@ function amazon_update_7100() { array('type' => 'varchar', 'length' => 32)); return(t("Updated currency code column types")); } + +/** + * Amazon has stopped providing customer review data; now we only get an + * iframe link where Amazon will provide the data, so we need to drop the table + * that was used for customer reviews and add the new iframe link. + */ +function amazon_update_7102() { + if (!db_field_exists('amazon_item', 'customerreviews_iframe')) { + db_add_field('amazon_item', 'customerreviews_iframe', array('type' => 'varchar', 'length' => 255)); + } + if (db_table_exists('amazon_item_customer_review')) { + db_drop_table('amazon_item_customer_review'); + } + // Expire all the existing amazon items so the next cron will update them. + db_update('amazon_item') + ->fields(array('timestamp' => 0)) + ->execute(); + + return(t("Updated support for customer reviews")); +} diff --git amazon.module amazon.module index 2b0db68..d5ae0b8 100644 --- amazon.module +++ amazon.module @@ -9,7 +9,7 @@ * save configuration and setup. */ -define('AMAZON_ECS_SCHEMA', '2009-03-31'); +define('AMAZON_ECS_SCHEMA', '2010-09-01'); define('AMAZON_PARTICIPANT_TYPES', 'Author,Artist,Actor,Director,Creator'); // Other common sizes include SwatchImage, TinyImage, and ThumbnailImage. @@ -155,14 +155,7 @@ function template_preprocess_amazon_item(&$variables, $theme_type) { $variables['type'] = _amazon_clean_type($item['producttypename']); $variables['detailpageurl'] = check_url($item['detailpageurl']); $variables['editorialreview'] = !empty($item['editorialreviews']) ? filter_xss($item['editorialreviews'][0]['content']) : ''; - if (!empty($item['customerreviews'])) { - foreach ($item['customerreviews'] as &$review) { - $review['content'] = filter_xss($review['content']); - $review['summary'] = filter_xss($review['summary']); - } - } - $variables['customerreview'] = !empty($item['customerreviews']) ? filter_xss($item['customerreviews'][0]['content']) : ''; - $variables['invalid_asin'] = !empty($item['invalid_asin']) ? 1 : 0; + $variables['customerreviews_iframe'] = !empty($item['customerreviews_iframe']) ? check_url($item['customerreviews_iframe']) : ''; $variables['invalid_asin'] = !empty($item['invalid_asin']) ? 1 : 0; $variables['detailpageurl'] = check_url($variables['detailpageurl']); @@ -633,14 +626,7 @@ function amazon_item_clean_xml($xml) { // And the customer reviews. if (isset($xml->CustomerReviews)) { - foreach ($xml->CustomerReviews->Review as $data) { - $item['customerreviews'][] = array( - 'rating' => (string) $data->Rating, - 'date' => (string) $data->Date, - 'summary' => (string) $data->Summary, - 'content' => (string) $data->Content, - ); - } + $item['customerreviews_iframe'] = (string)$xml->CustomerReviews->IFrameURL; } // Give other modules an opportunity to pull out other bits of Amazon data @@ -741,24 +727,6 @@ function amazon_item_insert($item) { } } } - // Save the customer reviews if they exist. - if (in_array('customer_reviews', variable_get('amazon_core_data', array('creators', 'images')))) { - if (isset($item['customerreviews'])) { - foreach ($item['customerreviews'] as $data) { - $review = array('asin' => $item['asin'], 'rating' => $data['rating'], 'date' => $data['date'], 'summary' => $data['summary'], 'content' => $data['content']); - try { - db_insert('amazon_item_customer_review') - ->fields($review) - ->execute(); - } - catch (Exception $e) { - amazon_db_error_watchdog("Failed to insert item into amazon_item_editorial_review table", $e); - } - - } - } - } - module_invoke_all('amazon_item_insert', $item); } @@ -782,9 +750,6 @@ function amazon_item_delete($asin) { db_delete('amazon_item_editorial_review') ->condition('asin', $asin) ->execute(); - db_delete('amazon_item_customer_review') - ->condition('asin', $asin) - ->execute(); } /** diff --git includes/amazon.views.inc includes/amazon.views.inc index b03cc7f..e2d8df2 100644 --- includes/amazon.views.inc +++ includes/amazon.views.inc @@ -217,19 +217,7 @@ function amazon_views_data() { _amazon_make_simple_text_field($data, 'amazon_item_editorial_review', 'source', 'Editorial review source', 'The source of this editorial review. Since there may be more than one review for each product, your view will produce one row per review.'); _amazon_make_simple_markup_field($data, 'amazon_item_editorial_review', 'content', 'Editorial content', 'Content of an editorial review. Since there may be more than one review for each product, your view will produce one row per review.'); - $data['amazon_item_customer_review']['table']['group'] = t('Amazon'); - $data['amazon_item_customer_review']['table']['join'] = array( - // customer review links to amazon_item directly via asin. - 'amazon_item' => array( - 'left_field' => 'asin', - 'field' => 'asin', - ), - ); - _amazon_make_simple_number_field($data, 'amazon_item_customer_review', 'rating', 'Customer Rating', "Numeric rating of this product. Since there is normally more than one review for each product, your view will produce one row per review."); - _amazon_make_simple_date_field($data, 'amazon_item_customer_review', 'date', 'Customer Rating Date', 'Date the product was rated. Since there is normally more than one review for each product, your view will produce one row per review.'); - _amazon_make_simple_text_field($data, 'amazon_item_customer_review', 'summary', 'Customer Review Summary', 'Summary of the review. Since there is normally more than one review for each product, your view will produce one row per review.'); - _amazon_make_simple_text_field($data, 'amazon_item_customer_review', 'content', 'Customer Review Content', 'Customer review content. Since there is normally more than one review for each product, your view will produce one row per review.'); - + _amazon_make_simple_text_field($data, 'amazon_item', 'customerreviews_iframe', 'Customer reviews iframe', "A link to an customer reviews provided by Amazon which is suitable for placement in an iframe"); return $data; }