我有一个wordpress自定义导入插件,工作正常,但由于某种原因,它无法在新的wordpress install Dropbox link中工作。插件会查找两个Feed文件barneys_feed.txt& barneyswarehouse_feed.txt(包含在插件中)应该在插件设置页面Detailed Description中配置。激活时,必须创建自定义表,但不创建,并且在产品运行中,以下内容显示在日志中:
[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
答案 0 :(得分: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
你应该在这做两件事:
$file = null
)$file
调用之前处理仍然具有空get_line
对象的情况。答案 1 :(得分:0)
错误消息告诉您,在某些时候,get_line
的{{1}}函数只会sjr\product_import\SJR_Product_Import
而不是SplFileObject
的实例。
我猜测null
函数看起来像这样:
get_line
你可以做什么(假设你自己编写代码),就是将函数更改为:
public function get_line(SplFileObject $file) { /* do some stuff */ }
告诉PHP除了对象之外,还接受null作为默认值。在这种情况下,您必须更新函数,以检查给定变量是否为空。您可以使用
进行检查
public function get_line(SplFileObject $file=null) { /* do some stuff */ }
我的身边完全猜测,正如错误所说,该位置包含if (!is_null($file)) {
/* every thing is fine */
} else {
/* there was an error, maybe write it to a error log */
}
我假设,PHP代码在NAS上运行并且有一些驱动器映射,您可以从中尝试定期导入一些东西,因为导入是由一个cron作业启动的。也许其中一个映射驱动器以某种方式丢失了连接,因此PHP无法读取文件。但正如我所说,这只是一个疯狂的猜测。到&#34;调试&#34;这样,您可以在运行cron作业时手动检查映射驱动器的状态,如果问题仍然存在,请查看。另一件事可能是,PHP(或更确切地说,Apache或Nginx)没有权限访问这些文件/共享。