--- ezrecommendation/bin/initialdataexport.php 2012-12-31 10:44:18.482376256 +0100 +++ ezrecommendation/bin/initialdataexport.php 2012-12-31 11:31:08.000000000 +0100 @@ -20,10 +20,12 @@ $ini = eZINI::instance( 'ezrecommendation.ini' ); $options = $script->getOptions( - "[split:][classgroup:]", + "[split:][classgroup:][parent_tree:][limit:]", "", array ( 'split' => 'Define how many entrys are defined in each ezrecommendation initial XML export file. ', - 'classgroup' => 'Filter classes by group, default group is 1 (Content)' ) + 'classgroup' => 'Filter classes by group, default group is 1 (Content)', + 'parent_tree' => 'Subtree parent node ID. Default is 2.', + 'limit' => 'Amount of items to fetch in each iteration. Default is 1000.' ) ); $split = $options[ 'split' ]; if ( $split == "" ) @@ -49,6 +51,14 @@ $script->shutdown( 1 ); } +$parent_tree = $options[ 'parent_tree' ]; +if ( !$parent_tree ) + $parent_tree = 2; //Home + +$limit = $options[ 'limit' ]; +if ( !$limit ) + $limit = 1000; + $url = $ini->variable( 'BulkExportSettings', 'SiteURL' ); $path = $ini->variable( 'BulkExportSettings', 'BulkPath' ); if ( empty( $url ) || empty( $path ) ) @@ -89,22 +99,29 @@ } $object_param_array = array(); -$parent_tree = 2 ; //Home +$offset = 0; foreach ( $classArray as $class_id ) { - $node_rows = $db->arrayQuery( "SELECT `node_id`,`contentobject_id`,`path_string` FROM `ezcontentobject_tree` where `contentobject_id` in (SELECT `id` FROM `ezcontentobject` where `contentclass_id` = $class_id) " ); - - foreach ( $node_rows as $node_id ) + $rows_count = $db->arrayQuery( "SELECT COUNT(*) AS count FROM `ezcontentobject_tree` where `contentobject_id` in (SELECT `id` FROM `ezcontentobject` where `contentclass_id` = $class_id) " ); + $numRows = $rows_count[0]['count']; + $cli->output( "Total count for class_id ($class_id): $numRows" ); + while ($numRows > $offset) { - $path_string = str_replace( '/1/', '', $node_id['path_string'] ); - $arr_path_string = preg_split( "/\//", $path_string ); - if ( $path_string[0] == $parent_tree ) - array_push( $object_param_array, array( "node_id" => $node_id['node_id'], - "object_id" => $node_id['contentobject_id'], - "node_path" => '/' . $path_string, - "class_id" => $class_id - ) + $node_rows = $db->arrayQuery( "SELECT `node_id`,`contentobject_id`,`path_string` FROM `ezcontentobject_tree` where `contentobject_id` in (SELECT `id` FROM `ezcontentobject` where `contentclass_id` = $class_id) ", array( 'offset' => $offset, 'limit' => $limit ) ); + foreach ( $node_rows as $node_id ) + { + $path_string = str_replace( '/1/', '', $node_id['path_string'] ); + $arr_path_string = preg_split( "/\//", $path_string ); + if ( in_array( $parent_tree, $arr_path_string ) ) + array_push( $object_param_array, array( "node_id" => $node_id['node_id'], + "object_id" => $node_id['contentobject_id'], + "node_path" => '/' . $path_string, + "class_id" => $class_id + ) ); + } + $cli->output( "Offset: " . $offset . " Count: " . count( $object_param_array ) ); + $offset += $limit; } } @@ -326,7 +343,7 @@ $elementTypeContentChild = $doc->createElement( 'content-data' ); $elementTypeContentChild->setAttribute( 'key', key( $contentvalue ) ); $elementTypeContentChild->appendChild( $doc->createCDATASection( - current( $contentvalue ) + utf8_encode(current( $contentvalue )) ) ); $elementTypeContent->appendChild( $elementTypeContentChild ); @@ -360,6 +377,10 @@ $fh = fopen( $filename, 'w' ); fwrite( $fh, $pushingItemDoc ); fclose( $fh ); + + $handler = eZClusterFileHandler::instance( $filename ); + $handler->fileStore( $filename ); + $cli->output( 'done' ); $xml_files [] .= 'bulkexport_' . $i . '.xml' ;