2014-03-24 36 views
0

使用Cron運行供應商進口商時,進口商超時導致進口不完整。我試圖用一個腳本來執行的進口商和我遇到這個代碼幾次:Drupal:以編程方式運行進口進口商 - 代碼的放置位置

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

然而,執行此,當我得到一個錯誤說沒有feeds_source()函數,這導致我相信我只是不知道該把代碼放在哪裏(一個單獨的php文件只是不適合我)。有人可以幫我從這裏出去嗎?提前致謝!

回答

0

我認爲你需要調用$source->startImport();方法instaed的$source->import();

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中調用,或者使用來自供應商的預定執行進口商