【问题标题】:Drupal: Running Feeds Importer Programatically - Where to Put CodeDrupal:以编程方式运行 Feeds Importer - 将代码放在哪里
【发布时间】:2014-03-24 17:43:25
【问题描述】:

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

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

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

【问题讨论】:

    标签: drupal-7 drupal-feeds


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我刚刚在这里发布了一个类似问题的答案: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 调用,或者使用提要导入器的计划执行

      【讨论】:

        猜你喜欢
        • 2014-09-21
        • 1970-01-01
        • 1970-01-01
        • 2015-11-19
        • 2014-11-21
        • 1970-01-01
        • 2018-03-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多