- I have a custom entity type and use Feeds to populate the entities. All works great on initial import.
- I then run a cron job that updates some fields of the entity that are not imported from the feed by accessing an external API. Again, works great.
Finally, I try to reimport the feed and any entity that was updated in step 2 now produces the error
The rovi game Metroid Prime 2: Echoes (21032) failed to validate with the following errors:: The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.Please check your mappings.
The processor settings are:
Insert new rovi games
[*] Insert new rovi games
[ ] Do not insert new rovi gamesUpdate existing rovi games
[ ] Do not update existing rovi games
[ ] Replace existing rovi games
[*] Update existing rovi gamesPreviously imported items
UnpublishExpire rovi games
NeverAdvanced settings
[✓]New Revision
Is there any way to get feeds to reimport even when the entity has been modified?
Here is the (sanitized) code that the cron job is running.
/** * Implements hook_cron(). */function msul_rovi_games_cron(){ define('ITEMS_PER_CRON',175); define('STALE_ITEM_UPDATE_TIME',strtotime("-30 days")); $nextOffset = \Drupal::state()->get('msul_rovi_games.last_game_id',0); $count = {{get total number of items}}; if($nextOffset>$count){ $nextOffset = 0; } $gameIDsToProcessQuery = \Drupal::entityQuery('rovi_game'); $gameIDsToProcessQuery ->accessCheck(FALSE) ->condition('changed',STALE_ITEM_UPDATE_TIME,'<=') ->range($nextOffset,ITEMS_PER_CRON); $gameIDsToProcess = $gameIDsToProcessQuery->execute(); $gamesToProcess = \Drupal::entityTypeManager() ->getStorage('rovi_game') ->loadMultiple($gameIDsToProcess); $client = new Client(); foreach($gamesToProcess as $key=>$game){ // compute catalog query $callNumber = {{Compute Call Number from other info}}; if($game->changed->getValue()[0]['value'] < STALE_ITEM_UPDATE_TIME){ try { $response = {{some api call}}; $records = json_decode($response->getBody(),TRUE); } catch(RequestException $e){ //error handling } $record = $records['records'][0]; // if found in catalog, update to match catalog $changed=FALSE; if(!isset($game->cataloged->getValue()[0]['value']) || $game->cataloged->getValue()[0]['value'] != TRUE){ $game->set('cataloged',TRUE); $changed=TRUE; } //similar if clause repeated for other fields if($changed){ $game->set('changed',time()); $game->save(); } } } \Drupal::state()->set('msul_rovi_games.last_game_id', $nextOffset + ITEMS_PER_CRON);}