コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see extension/sqliimport/classes/sourcehandlers/ISQLIImportHandler::initialize()
  */
 public function initialize()
 {
     $rssFeedUrl = $this->handlerConfArray['RSSFeed'];
     $xmlOptions = new SQLIXMLOptions(array('xml_path' => $rssFeedUrl, 'xml_parser' => 'simplexml'));
     $xmlParser = new SQLIXMLParser($xmlOptions);
     $this->dataSource = $xmlParser->parse();
 }
コード例 #2
0
 /**
  * (non-PHPdoc)
  * @see extension/sqliimport/classes/sourcehandlers/ISQLIImportHandler::initialize()
  */
 public function initialize()
 {
     $atomFeedUrl = $this->handlerConfArray['ATOMFeed'];
     $xmlOptions = new SQLIXMLOptions(array('xml_path' => $atomFeedUrl, 'xml_parser' => 'simplexml', 'timeout' => 10000));
     $xmlParser = new SQLIXMLParser($xmlOptions);
     $this->dataSource = $xmlParser->parse();
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see extension/sqliimport/classes/sourcehandlers/ISQLIImportHandler::initialize()
  */
 public function initialize()
 {
     $xmlUrl = $this->handlerConfArray['XMLStream'];
     $xmlString = eZHTTPTool::getDataByURL($xmlUrl);
     $xmlOptions = new SQLIXMLOptions(array('xml_string' => $xmlString, 'xml_parser' => 'simplexml'));
     $xmlParser = new SQLIXMLParser($xmlOptions);
     // On recherche tous les products dans la catégorie HardRock/Metal (HAR)
     $fullXML = $xmlParser->parse();
     $fullXML->registerXPathNamespace('x', $this->handlerConfArray['XMLNS']);
     $XPath = "//x:product[contains(./x:merchantCategory, '" . $this->handlerConfArray['MerchantCategory'] . "')]";
     $this->dataSource = $fullXML->xpath($XPath);
 }
コード例 #4
0
ファイル: xml.php プロジェクト: lolautruche/sqliimport
try {
    // Default XML parser is DOM (SQLIXMLOptions::XML_PARSER_DOM)
    $options = new SQLIXMLOptions(array('xml_path' => $xmlFile));
    $parser = new SQLIXMLParser($options);
    $xmlDoc = $parser->parse();
    // $xmlDoc is DomDocument
    $items = $xmlDoc->getElementsByTagName('item');
    foreach ($items as $item) {
        $title = $item->getElementsByTagName('title')->item(0)->nodeValue;
        $cli->notice("RSS Item title : '{$title}'");
    }
} catch (SQLIXMLException $e) {
    $cli->error($e->getMessage());
}
$cli->notice();
$cli->notice('#########################');
$cli->notice("### Processing XML test file {$xmlFile} with SimpleXML");
$cli->notice('#########################');
$cli->notice();
try {
    $options2 = new SQLIXMLOptions(array('xml_path' => $xmlFile, 'xml_parser' => SQLIXMLOptions::XML_PARSER_SIMPLEXML));
    $parser2 = new SQLIXMLParser($options2);
    $simpleXMLDoc = $parser2->parse();
    // $simpleXMLDoc is SimpleXMLElement
    foreach ($simpleXMLDoc->channel->item as $item) {
        $cli->notice("RSS Item title : '{$item->title}'");
    }
} catch (SQLIXMLException $e) {
    $cli->error($e->getMessage());
}
$script->shutdown();
コード例 #5
0
    /**
     * Main method to process current row returned by getNextRow() method.
     * You may throw an exception if something goes wrong. It will be logged but won't break the import process
     * @param array $row Depending on your data format, can be DOMNode, SimpleXMLIterator, SimpleXMLElement, CSV row...
     * @throws Exception
     * @return void
     */
    public function process( $row )
    {
        $rootImport     = $this->importINI->variable( 'XMLImportSettings', 'RootImport' );
        $publisherInfos = $this->fileHandler->getPublisherInfosFromFolderName( $row['publisher'] );
        if ( empty( $publisherInfos['default_language'] ) ) {
            $publisherInfos['default_language'] = 'eng-GB';
        }
        $filePath       = eZSys::rootDir() . "/$rootImport/{$this->fileHandler->rootImportFolder}/{$publisherInfos['path']}/{$row['file']}";

        XMLImportMonitor::initFile( $row['file'], $publisherInfos['path'], $publisherInfos['id'], md5_file($filePath) );

        try
        {
            if ( empty( $row['file'] ) || empty( $publisherInfos['path'] ) )
                return;

            try
            {
                $xmlOptions = new SQLIXMLOptions( array(
                    'xml_path'   => $filePath,
                    'xml_parser' => 'dom'
                ) );

                $sqliXmlParser   = new SQLIXMLParser( $xmlOptions );
                $this->xmlParser = $sqliXmlParser->parse();
            }
            catch ( SQLIXMLException $e )
            {
                $this->triggerException( $row['file'], $publisherInfos['path'], $e, 4 );
            }

            $xslProcess = XMLImportMapping::getByFieldName('xsl_process', $publisherInfos['path']);

            if ( $xslProcess !== false )
            {
                if ( !isset($this->xmlTransformers[$publisherInfos['path']]) )
                {
                    try
                    {
                        $xslFolder   = $this->importINI->variable('XMLImportSettings', 'XSLTFolder');
                        $xmslOptions = new SQLIXMLOptions( array(
                            'xml_path'   => eZSys::rootDir() . '/extension/' . $xslFolder . '/' . $xslProcess,
                            'xml_parser' => 'dom'
                        ) );

                        $sqliXmlTransformer           = new SQLIXMLParser( $xmslOptions );
                        $path                         = $publisherInfos['path'];
                        $this->xmlTransformers[$path] = $sqliXmlTransformer->parse();
                    }
                    catch ( SQLIXMLException $e )
                    {
                        $this->triggerException( $row['file'], $publisherInfos['path'], $e, 4 );
                    }
                }

                // Configure the transformer
                $proc = new XSLTProcessor;
                $proc->importStyleSheet($this->xmlTransformers[$publisherInfos['path']]);
                $this->xmlParser = $proc->transformToDoc($this->xmlParser);
            }

            try
            {
                $xmlFieldBuilder = new XMLFieldBuilder( $this->xmlParser, $this->importINI );
            }
            catch ( RootNodeException $e )
            {
                $this->triggerException( $row['file'], $publisherInfos['path'], $e, 4 );
            }

            try
            {
                $xmlFieldMixer = new XMLFieldMixer( $xmlFieldBuilder, $this->xmlParser, $this->importINI, $publisherInfos, $this->rootImportFolder );
                $fieldArray    = $xmlFieldMixer->process();
            }
            catch ( MandatoryException $e )
            {
                $this->triggerException( $row['file'], $publisherInfos['path'], $e, 3 );
            }
            try
            {
                XMLImportDataHandler::updateMdd( $fieldArray );
            }
            catch ( XMLImportDBException $e )
            {
                XMLImportDB::rollbackQuery();

                $e = new Exception( $e->getMessage() . "\n" . 'SQL action failed - Transaction will be rollbacked - Error Message : ' . XMLImportDB::getErrorMessage() );

                $this->triggerException( $row['file'], $publisherInfos['path'], $e, 5 );
            }

            //Archive XML and blobed files
            $this->fileHandler->archiveFiles( $publisherInfos['path'], $row['file'], $xmlFieldMixer->blobedFiles );

        }
        catch ( Exception $e )
        {
            XMLImportMonitor::commitFile();
            throw $e;
        }

        $this->fileHandler->dataSourcesCompleted++;

        XMLImportMonitor::commitFile();
    }