Wordpress Custom Import Plugin Not working - php

I have a wordpress custom import plugin which was working fine, but for some reason it is not working in a new wordpress install Dropbox link. Plugin looks for two feed files barneys_feed.txt & barneyswarehouse_feed.txt (included with plugin) which should be configured in plugin settings page Detailed Description. On activation a custom table has to be created but not creating and on product run following is displayed in log:
[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
Not able to reach out plugin developers. Please help. Thanks.
Update:
Following is the error i am getting now.
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

Something I find helpful for debugging these kinds of issues is looking at the stack trace of where your error is. You can print the stack trace at each of the debug_backtrace() at each of the locations you call get_line to see what is on the stack when you get the failed call.
I don't have your project up at this time, but it looks like your $file object is no longer in scope (and therefore null) for this call to 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
You should do two things here:
Define $file before the if statement (likely as $file = null)
Handle the case of still having a null $file object after the if statement and before the problem get_line call.

The error message tells you, that at some point, the get_line function of sjr\product_import\SJR_Product_Import gets instead of an instance of SplFileObject just a null.
I'm guessing the get_line function looks something like this:
public function get_line(SplFileObject $file) { /* do some stuff */ }
What you can either do (assuming you wrote that code on your own), is to change the function to something like this:
public function get_line(SplFileObject $file=null) { /* do some stuff */ }
telling PHP that besides the object, you also accept null as a default value. In that case, you would have to update your function, to check if the given variable is null. You can check this for example with
if (!is_null($file)) {
/* every thing is fine */
} else {
/* there was an error, maybe write it to a error log */
}
A completely guess from my side, as the error states, that the location contains /nas/ I'm assuming, that the PHP code is run on a NAS and has some drives mapped, from which you try to import some stuff periodically, as the import is started by a cron job. Maybe one of those mapped drives somehow lost the connection and therefore PHP wasn't able to read the files. But as I said, that's just a wild guess. To "debug" this, you could check the status of the mapped drives manually when the cron job is run and see, if the problem still happens. Another thing could be, that PHP (or more precise, Apache or Nginx) doesn't have rights to access those files/shares.

Related

PHP Cannot redeclare function/Call to undefined function

I am using WooCommerce on Wordpress 4.7.1. Previously, I was running 4.7.0. When Wordpress automatically upgraded to 4.7.1, I suddenly began seeing checkouts fail to redirect to the "Thank you" page, and the UI showed that a fatal error had occurred.
Turning on debugging revealed the following error:
PHP Fatal error: Cannot redeclare get_cc() (previously declared in .../templates/emails/email-addresses.php:36) in .../templates/emails/email-addresses.php on line 36
I also confirmed that this file is never directly called with require, require_once, include, or include_once. It is, however, called with wc_get_template().
A quick search brought me to this similar question. So I added the following to email-addresses.php:
if (!function_exists('get_cc')) {
function get_cc( $code ) {
... function body
}
}
After making this change, I now receive the following error in the debug log:
PHP Fatal error: Call to undefined function get_cc() in .../templates/emails/email-addresses.php on line 32
This means that, for whatever reason, PHP believes that the function get_cc already exists, but at the same time it is undefined.
I was not the original developer. I took over the project from a contractor who is not available. It does seem clear that this file is heavily modified from the original. I am certain that the value returned by the function must be kept, so I cannot just comment out the call.
Given the information above, what options do I have to either workaround or fix this issue?
It turns out that, unlike a standard function definition in PHP, function definitions wrapped in if (!function_exists('function_name')) { ... } block must precede any call to that function.
In this case, the function definition (line 36) followed the call (line 32). This caused the function to appear to PHP as undefined:
// Not working!
$value = get_cc($code);
if (!function_exists('get_cc')) {
function get_cc( $code ) {
...
}
}
Switching the order so that the function definition came first fixed the issue:
// Working!
if (!function_exists('get_cc')) {
function get_cc( $code ) {
...
}
}
$value = get_cc($code);
As of right now, PHP's documentation does not mention this issue.

Not able to decode ionCube encoded Smarty(3.1.18) Template files

I have used ionCube(ver. 8.3) to encrypt .tpl,.php files including smarty library files, I am able to encode them successfully with all Obfuscation options checked and able to generate Key file also. But when I try to open my index.php page it gives me following error ...
Fatal error: Uncaught exception 'LogicException' with message 'Function 'smartyAutoload' not found (function 'smartyAutoload' not found or invalid function name)' in C:\cc\htdocs\App_Encode\Smarty\libs\Smarty.class.php:0 Stack trace: #0 C:\cc\htdocs\App_Encode\Smarty\libs\Smarty.class.php(0): obfuscated #1 C:\cc\htdocs\App_Encode\index_standard_creation.php(0): unknown() #2 {main} thrown in C:\cc\htdocs\App_Encode\Smarty\libs\Smarty.class.php on line 0
The patch which is provided by ionCube is for Smarty 2.*
..since I am using Smarty 3.1.18 version and PHP Ver. 5.5...
I am not able to understand where problem lies as I am new to PHP programming.
I have tried following patch in getContent() function in \libs\plugins\smarty_internal_resource_file.php ..But it's no use :(
public function getContent(Smarty_Template_Source $source)
{
if ($source->timestamp) {
if (function_exists('ioncube_read_file')) {
return ioncube_read_file($source->filepath);
} else {
return file_get_contents($source->filepath);
}
}
if ($source instanceof Smarty_Config_Source) {
throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
}
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
}
Please help me out!!
You've used the good patch for Smarty 3 from http://www.smarty.net/forums/viewtopic.php?t=20562
You must also encode Smarty, or at least the patched file, as ioncube_read_file() can only be used in an encoded file (in this scenario it would be pointless to have a decrypt routine in a non-encoded file). ioncube_read_file() will return an error code as an integer instead of the file contents as a string if there is an error, so you could extend the patch to test for that and log the error code somewhere. The error codes also exist as constants defined by the ionCube Loader, and the codes and constants are documented in the User Guide PDF.

PHP CallFire SDK - Authentication and Request/Response problems

Disclaimer: php novice student working really hard here.
I'm trying to build an app that interacts with the CallFire API.
At this point all I'm trying to achieve is establishing a communication with the API and succesfully getting a request/response cycle going.
I have installed the Callfire SDK dependency with Composer on my XAMPP local server. I want to get this very basic example running: it instantiates the API, sends a request and parses the response.
<?php
use CallFire\Api\Rest\Request;
require 'vendor/autoload.php';
$client = CallFire\Api\Client::Rest("<api-login>", "<api-password>", "Broadcast"); //I'm using my valid CallFire API keys here.
$request = new Request\QueryBroadcasts;
$response = $client->QueryBroadcasts($request); //LINE 10
$broadcasts = $client::response($response);
foreach($broadcasts as $broadcast) {
var_dump($broadcast);
}
I put this code in a index.php file and when I run it in my browser I get:
Notice: Trying to get property of non-object in C:\xampp\htdocs\cfireapi1\vendor\callfire\php-sdk\src\CallFire\Api\Rest\Response.php on line 39
Notice: Trying to get property of non-object in C:\xampp\htdocs\cfireapi1\vendor\callfire\php-sdk\src\CallFire\Api\Rest\Response.php on line 39
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Response type not recognized' in C:\xampp\htdocs\cfireapi1\vendor\callfire\php-sdk\src\CallFire\Api\Rest\Response.php:50
Stack trace: #0 C:\xampp\htdocs\cfireapi1\vendor\callfire\php-sdk\src\CallFire\Api\Rest\AbstractClient.php(59): CallFire\Api\Rest\Response::fromXml(false)
#1 C:\xampp\htdocs\cfireapi1\index.php(10): CallFire\Api\Rest\AbstractClient::response(false)
#2 {main} thrown in C:\xampp\htdocs\cfireapi1\vendor\callfire\php-sdk\src\CallFire\Api\Rest\Response.php on line 50
Line 59 in AbstractClient.php is
public static function response($data, $type = self::FORMAT_XML)
{
if (is_string($data) && strlen($data) === 0) {
return true; // Many operations return an empty string for success
}
switch ($type) {
case static::FORMAT_XML:
return AbstractResponse::fromXml($data); // LINE 59
case static::FORMAT_JSON:
return AbstractResponse::fromJson($data);
}
throw new InvalidArgumentException("Type must be 'xml' or 'json'");
}
And lines 39 and 50 in Response.php are
public static function fromXml($document)
{
$document = static::getXmlDocument($document);
// return print_r($document);
switch ($document->firstChild->nodeName) { // LINE 39 error for this line is Notice: Trying to get property of non-object
case 'r:ResourceList':
return Response\ResourceList::fromXml($document);
case 'r:Resource':
return Response\Resource::fromXml($document);
case 'r:ResourceReference':
return Response\ResourceReference::fromXml($document);
case 'r:ResourceException':
return Response\ResourceException::fromXml($document);
}
throw new UnexpectedValueException('Response type not recognized'); // LINE 50: this is what throws the fatal error exception
}
Line 10 is highlighted in the example code.
So I know that the API is sending back an response with an unidentified type. Why, if I'm literally using the SDK and one of the basic examples in the documentation? How can I check the response that I'm getting to see what it is exactly? I tried printing the response with r_print inside the Response.php file but I got a "1" printed in the browser. Which makes not sense to me. Is it because I'm running this in the browser?
SOLVED: Somehow running the program in the localhost environment was causing the problem. Everything worked once I uploaded the application into my server.

Is it possible to mimic PHPUnit's output-to-console results using a Listener?

Situation
I'm implementing a Listener for PHPUnit that will record test results to a DB for later review. I like the default information phpunit outputs to console when a failure, error, skipped, or incomplete test is encountered.
Example:
1) sandbox_ExtensionSampleTest::testError
printf(): Too few arguments
E:\ecom_testing\tests_v2\TestSuites\sandbox\Base.php:28
E:\ecom_testing\tests_v2\TestSuites\sandbox\ExtensionSampleTest.php:37
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:939
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:801
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestResult.php:649
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:748
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestSuite.php:772
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestSuite.php:745
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\TestRunner.php:325
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\Command.php:187
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\Command.php:125
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\phpunit:44
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Note: I did find listing all the PHPUnit dependencies in the output is a bug, but the example above still shows two related test files.
Question
One of the parameters for an implemented listener method is Exception $e. I can get the message as well as the first line using $e, but I can't seem to get the rest of the lines.
After reading Exceptions in the PHP manual, I thought using $e->getPrevious() would work... attempted to do the following:
// Storing in a array to put into a DB later
// First line with the message
$trace[] = sprintf(
"%s\n\n%s:%s\n",
$e->getMessage(),
$e->getFile(),
$e->getLine()
);
// Go through the rest of the exceptions of files and lines
while ($e = $e->getPrevious()){
$trace[] = sprintf(
"%s:%s\n",
$e->getFile(),
$e->getLine()
);
}
That didn't work. It seems like $e->getPrevious() is empty and I did confirmed it when I dumped the object. I thought something like $e->getTraceAsString() would yield the same results, but it's not what I expected (I haven't used exceptions much)
The list of file and line number combinations is called the stack trace. You can grab it as an array using Exception::getTrace() and walk it yourself, or you can let PHPUnit filter out its classes for you by calling PHPUnit_Util_Filter::getFilteredStacktrace(). Pass the exception $e and true to receive a formatted string, or pass false to get the filtered array back instead.

Session error using Laravel PHP

I get this error when enabling sessions, using the filesystem, in Laravel PHP.
Only variables should be passed by reference in SYS_PATH/session.php on line 230.
Stack Trace:
0 /Applications/XAMPP/xamppfiles/htdocs/laravel/system/session.php(230): System\{closure}(2048, 'Only variables ...', '/Applications/X...', 230, Array)
1 /Applications/XAMPP/xamppfiles/htdocs/laravel/system/session.php(190): System\Session::write_cookie()
2 /Applications/XAMPP/xamppfiles/htdocs/laravel/system/laravel.php(187): System\Session::close()
3 /Applications/XAMPP/xamppfiles/htdocs/laravel/public/index.php(44): require('/Applications/X...')
4 {main}
Snapshot:
225: */
226: private static function write_cookie()
227: {
228: if ( ! headers_sent())
229: {
230: extract(Config::get('session'));
231:
232: $minutes = ($expire_on_close) ? 0 : $lifetime;
233:
234: Cookie::put('laravel_session', static::$session['id'], $minutes, $path, $domain, $https, $http_only);
235: }
Has anybody run into this issue? Even if you don't use Laravel, any insight?
That you're seeing the error message is a flaw in the Laravel PHP framework.
The session class makes use of the extract function that is expecting a variable, but it get's a function return.
I have reported this behavior to the project and you can discuss the options with them as well. You find a suggestion how to fix it attached, let me know if that works for you.
What if instead of extracting the config to your local scope you just assign it to an array, and use those values? The error seems to be there, not with sessions.

Categories