eZ Community » Forums » Developer » ezpublish 4 legacy api export content...
expandshrink

ezpublish 4 legacy api export content of ezxmltext datatype

ezpublish 4 legacy api export content of ezxmltext datatype

Wednesday 15 October 2014 5:25:33 pm - 1 reply

Hey guys,

I have a question that hopefully someone else knows the answer to.

We have 2 sites in production. One implemented on eZ4 and one implemented in eZ5. Now I have created a command on the new site to import some content from the old site, using the data provided through the API endpoints like  :

...api/ezp/content/node/13443/list?ResponseGroups=Metadata,Fields

Everything seems OK, just that we are not able to retrieve the html content of the attributes XMLBlock because the API returns the content without any HTML or XML tags.

Any suggestions here? 

I was thinking into digging into the API and customizing it but would rather have a second opinion before doing this.

Thanks in advance

Modified on Wednesday 15 October 2014 5:30:18 pm by Maior Valentin

Thursday 16 October 2014 4:03:34 pm

Finally, I decided to create an extension that overrides ezprestapiprovider.

The problem was actually that in ezpRestContentModel there was:

    case 'ezxmltext':               

     $html = $field->content->attribute( 'output' )->attribute( 'output_text' );               

    $attributeValue = array( strip_tags( $html ) );

    break; 

So I created a new extension that extends all the classes of the initial extension and in settings/rest.ini.append.php I addedd 

[ApiProvider]ProviderClass[ezp]=MyRestApiProvider

 

All the other classes just extended the original classes like this:

(myextension/classes/controllers)

     class MyRestContentModel extends ezpRestContentModel

    -- overriden public function doList()  and changed these lines

       $result->variables['childrenNodes'] = MyRestContentModel ::getChildrenList( $crit, $this->request, $this->getResponseGroups() );

       $childrenCount = MyRestContentModel ::getChildrenCount( $crit );

(myextension/classes/models)

    class MyRestContentModel extends ezpRestContentModel

      public static function attributeOutputData( ezpContentField $field )   {   

       if ($field->data_type_string == 'ezxmltext') {     

        $html = $field->content->attribute( 'output' )->attribute( 'output_text' );     

        $attributeValue = array($html);    }

       else {     

            $html = ezpRestContentModel::attributeOutputData($field);   

      }
    return $html; 

   }

INSIDE public static function getChildrenList changed ezpRestContentController to MyRestContentController

(myextension/rest_provider.php)

    class MyRestApiProvider extends ezpRestApiProvider

      function getRoutes()   {   

      $routes = parent::getRoutes();   

      $routes['ezpList'] = new ezpRestVersionedRoute(               

          new ezpMvcRegexpRoute( '@^/content/node/(?P<nodeId>\d+)/list(?:/offset/(?P<offset>\d+))?          (?:/limit/(?P<limit>\d+))?(?:/sort/(?P<sortKey>\w+)(?:/(?P<sortType>asc|desc))?)?$@',                    'MYRestContentController', 'list' ), 1                );    return $routes; 

}

(myextension/view_controller.php) --- nothing added just overriden

    class MyRestApiViewController extends ezpRestApiViewController

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from