Forums / Setup & design / RSS and the keywords attribute

RSS and the keywords attribute

Author Message

Børge Warvik

Monday 07 May 2007 1:20:59 am

Hi,

In our system we're going to use the keywords attribute in classes to display relevant nodes to the node that is being viewed by the user.

At the moment I'm trying to set this up for our RSS imports. We're buying external news, and the news are delivered as a feed that I'm importing. The feed is RSS 2.0. I've told the company that delivers the feed to put the keywords they are using to create the feed into the RSS 2.0 "comments" field. In the RSS classed used to store the feed items I've added a field called Keywords of datatype keywords.

The keywords in the feed are a comma separated list of words. When done, I'm activating and start to import the items. Everything is working fine, except that the keywords aren't being imported into the keywords field in the RSS class.

Any ideas why this is happening?

Thanks,
Børge Warvik

Egil Fujikawa Nes

Thursday 10 May 2007 10:25:36 am

Hi Børge,

I'm not sure I can give you a out-of-the-box solution, but I have a clue that you can work with. I experienced problem with importing data to the ezkeyword datatype but not from the default RSS import script in eZ.

When I look into the rssimport.php in you will see this code to write the value:

function setObjectAttributeValue( &$objectAttribute, $value )
{
    if ( $value === false )
    {
        return;
    }

    $dataType = $objectAttribute->attribute( 'data_type_string' );
    if ( $dataType == 'ezxmltext' )
    {
        setEZXMLAttribute( $objectAttribute, $value );
    }
    elseif ( $dataType == 'ezurl' )
    {
        $objectAttribute->setContent( $value );
    }
    else
    {
        $objectAttribute->setAttribute( 'data_text', $value );
    }

    $objectAttribute->store();
}

This shows that ezkeywords just will be tried inserted with the commaseparated string in setAttribute.

What you need to do in order to store a eZkeyword is to initialize a keyword object, my import code looks like this:

        $key = new eZKeyword();
        $key->initializeKeyword( $value );
        $keyword = $myContentObjectAttributes['keyword_trigger'];
        $keyword->setContent( $key );
        $keyword->store();

What I suggest is that you try to edit your rssimport.php to something like this:

function setObjectAttributeValue( &$objectAttribute, $value )
{
    if ( $value === false )
    {
        return;
    }

    $dataType = $objectAttribute->attribute( 'data_type_string' );
    if ( $dataType == 'ezxmltext' )
    {
        setEZXMLAttribute( $objectAttribute, $value );
    }
    elseif ( $dataType == 'ezurl' )
    {
        $objectAttribute->setContent( $value );
    }
    elseif ( $dataType == 'ezkeyword' )
    {
        $key = new eZKeyword();
        $key->initializeKeyword( $value );
        $objectAttribute->setContent( $key );
    }
    else
    {
        $objectAttribute->setAttribute( 'data_text', $value );
    }

    $objectAttribute->store();
}

I don't know if this will works out, but hopefully you got a idea about where the problem is located.

Good luck Børge :)

BuildCMS - Av. Paulista 777, 15° Andar - CEP: 01311-100 - São Paulo
URL: http://www.buildcms.com

Łukasz Serwatka

Thursday 10 May 2007 1:54:36 pm

There was a bug [1] fixed by Kåre in:
stable/3.8 rev. 18847
stable/3.9 rev. 18848
trunk rev. 18849

[1] http://issues.ez.no/10713

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog