Created
February 1, 2017 16:03
-
-
Save trouttdev/85e70dddf93d6bb3199f8ca853f97d22 to your computer and use it in GitHub Desktop.
Reject an entire feed import if a required field in feeds_tamper fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_feeds_after_parse(). | |
*/ | |
function my_module_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) { | |
// $sql = "SELECT COUNT(*) FROM feeds_log WHERE request_time = " . REQUEST_TIME . " AND id = " . $source->id . " AND type LIKE '%feeds_tamper:required%'" ; | |
$number_of_prase_errors = db_select('feeds_log', 'f') | |
->fields('f', array('flid')) | |
->condition('request_time', REQUEST_TIME, '=') | |
->condition('id', $source->id, '=') | |
->condition('type', '%feeds_tamper:required%', 'LIKE') | |
->countQuery()->execute()->fetchField(); | |
if ($number_of_prase_errors > 0) { | |
// unset all the items so nothing gets uploaded | |
$result->items = array(); | |
$args = array(); | |
$source->log('my_module:reject_upload', 'There was a problem with the uploaded file. Please correct the above errors and try again.', $args); | |
drupal_set_message(t('There was a problem with the uploaded file. Please correct the above errors and try again.', $args)); | |
} | |
} | |
/** | |
* Implements hook_module_implements_alter(). | |
* | |
* Make sure that our feeds_after_parse is called AFTER the same hook provided in feeds_tamper | |
*/ | |
function my_module_module_implements_alter(&$implementations, $hook) { | |
if ($hook == 'feeds_after_parse') { | |
// Move my_module_rdf_mapping() to the end of the list. module_implements() | |
// iterates through $implementations with a foreach loop which PHP iterates | |
// in the order that the items were added, so to move an item to the end of | |
// the array, we remove it and then add it. | |
$group = $implementations['my_module']; | |
unset($implementations['my_module']); | |
$implementations['my_module'] = $group; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment