0

使用 Cron 运行提要导入器时,导入器超时导致导入不完整。我正在尝试使用脚本来执行导入程序,并且我遇到过几次此代码:

<?php
function MODULE_NAME_cron() {
  $name = 'FEED_NAME';
  $source = feeds_source($name);
  $source->import();
}
?>

但是,执行此操作时,我收到一条错误消息,指出没有 feeds_source() 函数,这使我相信我只是不知道将这段代码放在哪里(单独的 php 文件对我不起作用)。有谁可以帮我离开这里吗?提前致谢!

4

2 回答 2

0

我刚刚在这里发布了一个类似问题的答案: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 导入器的预定执行

于 2015-03-31T16:23:40.463 回答
0

我认为您需要调用$source->startImport();方法而不是$source->import();

于 2014-03-26T13:42:11.290 回答