This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » using \eZOEInputParser() in sf2/ez5.x...
expandshrink

using \eZOEInputParser() in sf2/ez5.x command

using \eZOEInputParser() in sf2/ez5.x command

Thursday 06 March 2014 5:34:41 pm - 2 replies

Hello,

I try to import content from HTML. To do this i want to use \eZOEInputParser(). It do everything i need.

But when i use it, ia have strange error and the content is broken.

 

 
...
class myImportCommand extends ContainerAwareCommand
{
...
    protected function execute(InputInterface $input, OutputInterface $output)
    {
    ...
           // my html from my source           
           $myHTML ='
 
                    <p class="lettrine">L\'anti-spam int&eacute;gr&eacute; &agrave; l\'anti-virus firewall Lorem Ipsum (version 4) trie vos courriers &eacute;lectroniques et filtre les&nbsp;courriers ind&eacute;sirables. <br />Lorsque vous&nbsp;relevez vos messages &eacute;lectroniques &agrave; l\'aide de votre logiciel de messagerie (Outlook, Outlook express, Thunderbird, ...), l\'anti-spam va analyser les courriers qui arrivent dans votre bo&icirc;te de r&eacute;ception. <br />Si, parmi les messages re&ccedil;us, certains sont reconnus en tant que courrier ind&eacute;sirable, ils seront marqu&eacute;s par le logiciel de courrier ind&eacute;sirable et d&eacute;plac&eacute;s vers le dossier nomm&eacute; &quot;courrier ind&eacute;sirable&quot;.<br /><br />Le module de courrier ind&eacute;sirable va, apr&egrave;s l\'installation de l\'anti-virus firewall Lorem Ipsum version 4, automatiquement cr&eacute;er le dossier &quot;Courrier ind&eacute;sirable&quot; dans le logiciel de messagerie Outlook.<br />Si votre client de messagerie est autre (Outlook express, Thunderbird, ...) vous devez cr&eacute;er les r&egrave;gles de messages et le dossier nomm&eacute; &quot;courrier ind&eacute;sirable&quot;.<br /><br />Ces manipulations effectu&eacute;es, un tri automatique s\'op&eacute;rera sur le courrier arrivant dans la bo&icirc;te de r&eacute;ception de votre logiciel de messagerie.<br />Le filtrage sera fait au regard du moteur d\'analyse du logiciel de courrier ind&eacute;sirable, &eacute;galement &agrave; partir des filtres que vous avez cr&eacute;&eacute;s.<br /><a href="file.php">Cr&eacute;er des filtres pour le courrier ind&eacute;sirable</a>.</p>
          <br />
          <p class="titre_remarque">Remarque:</p>
          <p class="bloc_remarque">En d&eacute;pit de l\'automatisation du processus de filtrage, il peut arriver que des courriers soient, &agrave; tort dirig&eacute;s, vers le dossier de courrier ind&eacute;sirable.<br />Aussi, nous vous invitons &agrave; v&eacute;rifier les courriers d&eacute;plac&eacute;s dans ce dossier.</p>
          <br />
          <h3>Cr&eacute;er un dossier de courrier ind&eacute;sirable dans Mozilla Thunderbird</h3>
          <p><span class="procedure">1</span></p>
          <p>Lancer le logiciel Thunderbird.</p>
          <p><span class="procedure">2</span></p>
          <p>Dans le menu &quot;<strong><u>F</u>ichier</strong>&quot;, s&eacute;lectionnez &quot; <strong>Nouv<u>e</u>au</strong>&quot; puis &quot; <strong><u>D</u>ossier</strong> &quot;.</p>
          <p><img height="156" alt="Nouveau dossier" width="447" src="/Image/1734_01_nveau.png" /></p>
          ';
 
           // cleanup the HTML
           $tidy = tidy_parse_string (myHTML, array('output-xml'=>true ,'quote-nbsp'=>false, 'show-body-only'=>true, 'indent'=>true,'DocType' => 'omit'), 'utf8'); 
            
            //extract body content
            $matches =array();
            if (preg_match('/(?:<body[^>]*>blunk.gif Emoticon(.*)<\/body>/isU', $tidy, $matches)) {
                $body = $matches[1];
            }
            
            // parse and convert to DomDocument           
            $ezOEInputParser = new \eZOEInputParser();
            $dom  =$ezOEInputParser->process($body);
 
            // create value
            $value = new \eZ\Publish\Core\FieldType\XmlText\Value($dom);
            
            // create contentType and content
            $contentType = $contentTypeService->loadContentTypeByIdentifier( 'article' );
            $contentCreateStruct = $contentService->newContentCreateStruct( $contentType, 'fre-FR' );        
            // put data into content                    
            $contentCreateStruct->setField( 'title', 'My title' );
            $contentCreateStruct->setField( 'intro', $value );
            $contentCreateStruct->setField( 'body', $value );
            
            $locationCreateStruct = $locationService->newLocationCreateStruct( 2 );
            // let's go
            $draft = $contentService->createContent( $contentCreateStruct, array( $locationCreateStruct ) );
            $content = $contentService->publishVersion( $draft->versionInfo );
            
            
            ...

After few second a fatal error was generated.

 PHP Fatal error:  Call to a member function attribute() on a non-object in /var/www/ezpublish/ezpublish_legacy/kernel/search/plugins/ezsearchengine/ezsearchengine.php on line 53

Fatal error: eZ Publish did not finish its request
The execution of eZ Publish was abruptly ended, the debug output is present below.

What about of my code ?

Thanks you

Thomas

Modified on Thursday 06 March 2014 5:41:30 pm by Thomas Lecarpentier

Monday 10 March 2014 10:37:53 am

Hi Thomas

When you want to use legacy classes/components in the new stack, you need to call them from within the legacy kernel. See documentation on how to use it.

In a command, you won't have $this->getLegacyKernel() helper. You'll need to get it the following way:

$kernelClosure = $this->getContainer()->get( 'ezpublish_legacy.kernel' );
$legacyCallbackResult = $kernelClosure()->runCallback(
    // You can "import" variables in the closure with "use" keyword
    function ()
    {
        // Do something
        return $myResult;
    }
); 

Thursday 13 March 2014 11:14:03 am

Thank you Jérôme, it work perfectly.

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from