2016-11-23 12 views
-2

我有一個WordPress的定製導入插件工作正常,但由於某種原因,它不是在新的WordPress的安裝Dropbox link工作。插件查找兩個供稿文件barneys_feed.txt & barneyswarehouse_feed.txt(包含在插件中)應該在插件設置頁面Detailed Description中進行配置。在激活自定義表必須創建而不是創造和產品運行時顯示在日誌中以下內容:WordPress的自定義導入插件不工作

[Tue Nov 22 18:28:08.931419 2016] [:error] [pid 11484] [client 38.140.212.19:64906] PHP Catchable fatal error: Argument 1 passed to sjr\\product_import\\SJR_Product_Import::get_line() must be an instance of SplFileObject, null given, called in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 334 and defined in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 372, referer: http://testwindow.wpengine.com/wp-admin/options-general.php?page=sjr_product_import_settings 

未能達成了插件開發。請幫忙。謝謝。

更新: 以下是我現在得到的錯誤。

PHP Fatal error: Uncaught TypeError: Argument 1 passed to sjr\\product_import\\SJR_Product_Import::get_line() must be an instance of SplFileObject, null given, called in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 334 and defined in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php:372\nStack trace:\n#0 /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php(334): sjr\\product_import\\SJR_Product_Import->get_line(NULL, 1)\n#1 [internal function]: sjr\\product_import\\SJR_Product_Import->csv_to_database()\n#2 /nas/content/live/testwindow/wp-includes/plugin.php(600): call_user_func_array(Array, Array)\n#3 /nas/content/live/testwindow/wp-cron.php(117): do_action_ref_array('sjr_product_imp...', Array)\n#4 {main}\n thrown in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 372, referer: http://testwindow.wpengine.com/wp-cron.php?doing_wp_cron=1480412579.4279830455780029296875 
+1

您採取了哪些措施來嘗試解決這個問題? – smcjones

+0

嘗試轉到插件設置,並檢查**服務器路徑導入文件1 **和**服務器路徑導入文件2 **路徑;點擊**保存設置**,即使您看到文本框中填充了值。還請檢查這些文件路徑以存在於路徑中,並且您的WP應用程序可以訪問它們。 –

回答

0

對於調試這些類型的問題我覺得有幫助的東西是查看堆棧跟蹤錯誤的位置。您可以在您撥打get_line的每個位置打印每個debug_backtrace()處的堆棧跟蹤,以便在發生失敗的呼叫時查看堆棧中的內容。

我沒有你的項目了在這個時候,但它看起來像你的$file對象不再範圍(因此無效),此調用get_line

foreach($lines as $line_item){ 
    if($file_name != $line_item['file']){ 
     $file_name = $line_item['file']; 
     $basename = basename($file_name); 

     // get columns 
     $file = new \SplFileObject($file_name, 'r'); 
     $file->setFlags(\SplFileObject::READ_CSV); 
     $file->setCsvControl("\t", " "); 

     // get first row with column names 
     $first_row = $this->get_line($file, 0); 
    } // You lose scope on $file here 

    $row = $this->get_line($file, $line_item['line_number'] - 1); // <-- This one is the likely cause 

你應該做兩件事在這裏:

  1. 定義在if語句之前$文件(可能性是$file = null
  2. 手柄仍然有如果後一個空$file對象的情況下statemen t並在問題get_line之前致電。
0

錯誤消息告訴你,在某個時候,的sjr\product_import\SJR_Product_Importget_line函數獲取的,而不是SplFileObject只是null一個實例。

我猜get_line功能看起來是這樣的:
public function get_line(SplFileObject $file) { /* do some stuff */ }

你可以做什麼(假設你寫你自己的代碼),是將功能更改爲類似這樣: public function get_line(SplFileObject $file=null) { /* do some stuff */ }

告訴PHP,除了對象之外,您還接受null作爲默認值。在這種情況下,你將不得不更新你的函數,以檢查給定的變量是否爲空。您可以檢查此例如

if (!is_null($file)) { /* every thing is fine */ } else { /* there was an error, maybe write it to a error log */ }

一個從我身邊完全猜到,因爲錯誤狀態,該位置包含/nas/我假設,即PHP代碼在運行NAS並有一些驅動器映射,從中嘗試定期導入一些東西,因爲導入是由cron作業啓動的。也許其中一個映射驅動器失去了連接,因此PHP無法讀取這些文件。但正如我所說,這只是一個瘋狂的猜測。要「調試」這一點,您可以在cron作業運行時手動檢查映射驅動器的狀態,並查看問題是否仍然存在。另一件事可能是,PHP(或更確切地說,Apache或Nginx)無權訪問這些文件/共享。