creating express entries programmatically

Permalink
Anyone hear have success creating entries in a block.

using the code from the docs when including
use Express;

i get the error
"The use statement with non-compound name 'Express' has no effect"

when using
Express::buildEntry
I get
"Entity of type Concrete\Core\Entity\Attribute\Value\ExpressValue is missing an assigned ID for field 'attribute_key'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly."

of course the second may be caused by the first and the first may be caused by being in a block instead of a package install controller. I'm a hair out of my comfort zone here.

I'm trying to write some one time code to import some records and add them as entries. The import works fine i just cant add entries yet.

 
thirtythree replied on at Permalink Reply
I have the same error.

My code was working in 8.0.3, but now after updating to 8.1 I get that error.

$f = File::getByID(1);
        if (is_object($f))
        {
            $row = 1;
            if (($handle = fopen(ltrim($f->getRelativePath(), '/'), "r")) !== FALSE) {
              while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                $entry = Express::buildEntry('whitelisted_referrers')
                        ->setUuid($data[1])
                        ->setRefEmail($data[0])
                        ->setRefEntered(0)
                        ->save();
                $row++;
              }
              fclose($handle);
            }
thirtythree replied on at Permalink Reply
If it helps others, I think my issue here was the upgrade from 8.0.3 to 8.1.

There was no way of fixing it, apart from (manually) destroying the instance of my Express object and recreating it under 8.1

It now works.
TRRosen replied on at Permalink Reply
bummer, not my issue as i built on a clean copy of 8.1
AravindMJC5 replied on at Permalink Reply
Just found this issue myself. Any solutions?
I'm guessing it's a database thing. Oh, I'm on 8.2 by the way.