我刚刚在这里发布了一个类似问题的答案:https ://drupal.stackexchange.com/questions/90062/programmatically-execute-feed-import/153434#153434 ,这可能会有所帮助。简而言之,如果您使用批处理 api,请在表单中提交钩子,或者如果您在非浏览器中使用批处理 api(安装钩子,安装配置文件)
所以在你的情况下
function load_data(){
// Files to import in specific order.
$files = array(
'challenge_importer' => 'data/challenges.csv',
);
$file_location_base = drupal_get_path('module', 'challenge');
foreach ($files as $feed => $file) {
$feedSource = feeds_source($feed);
// Set the file name to import
$filename = $file_location_base.'/' . $file;
if (!file_destination($filename, FILE_EXISTS_ERROR)) {
$config = $feedSource->getConfig();
$config['FeedsFileFetcher']['source'] = $filename;
$feedSource->setConfig($config);
$feedSource->save();
while (FEEDS_BATCH_COMPLETE != $feedSource->import());
}
}
}
可以从 cron 调用,或者使用 feed 导入器的预定执行