I have a simple script to import entries into MT4 through the API:
use MT;
use MT::Author;
use MT::Object;
use MT::Entry;
my $entry = MT::Entry->new;
$entry->blog_id(1);
$entry->status(MT::Entry::RELEASE());
$entry->author_id(8);
$entry->title('My title');
$entry->text('Some text');
$entry->save()
or die $entry->errstr;
exit
When I run this script I get the following error:
Can't use an undefined value as a HASH reference at /var/www/cgi-bin/mt/lib/MT/Object.pm line 850.
What's missing that I don't have in this script or on the server?
Thank you in advance for any help.
Reported on Movable Type 4.2
You need the MT lib directories in your include path. Add:
use strict;
use lib ('./lib/', './extlib');
Assuming that you are calling this from inside the MT folder. Adjust the paths accordingly if not.
Mike,
Thanks for the help, this didn't help, but I have set the code to:
use strict;
use lib '/var/www/cgi-bin/mt/lib';
use lib '/var/www/cgi-bin/mt/extlib';
use MT;
use MT::Author;
use MT::Object;
require MT::Entry;
my $entry = MT::Entry->new;
$entry->blog_id(1);
$entry->status(MT::Entry::RELEASE());
$entry->author_id(8);
$entry->title('My title');
$entry->text('Some text');
$entry->save()
or die $entry->errstr;
exit
I'm not in the MT folder, but in my home directory.
Thank you.
Is $entry successfully initialized as a MT::Entry?
No, that's the line that the error appears on. I don't get past that line in the script.
I am pretty sure I just figured it out. It's a matter of the configuration data not being loaded. Add the following call to your code after the imports: my $mt = MT->instance();.
Mike T,
This resolved the issue. Thank you.
I just filed this away as a bug report (more of a cosmetic bug than a serious one).
I was facing the same issue... my $mt = MT->instance(); helped, thanks a ton MIke