public static function getXmlDetails( $xmlFile ) { $data = array(); $remoteIds = array(); $articleIds = array(); $sql = "SELECT * FROM import_status s WHERE s.xml_file='{$xmlFile}' ORDER BY s.version DESC"; $db = self::db(); $rows = $db->arrayQuery( $sql ); foreach ( $rows as $row ) { $data[$row['id']] = $row; if ( !empty( $row['remote_id'] ) ) { if ( !isset( $remoteIds[$row['remote_id']] ) ) { $remoteIds[$row['remote_id']] = array(); } $remoteIds[$row['remote_id']][] = $row['id']; } if ( !empty( $row['article_id'] ) ) { if ( !isset( $articleIds[$row['article_id']] ) ) { $articleIds[$row['article_id']] = array(); } $articleIds[$row['article_id']][] = $row['id']; } } if ( !empty( $remoteIds ) ) { $rows = ImportStatus::fetchObjectAndNodeIds( array_keys( $remoteIds ) ); foreach( $rows as $row ) { foreach( $remoteIds[$row['remote_id']] as $id ) { $data[$id]['node_id'] = $row['main_node_id']; $data[$id]['object_id'] = $row['id']; } } } if ( !empty( $articleIds ) ) { $rows = ImportStatus::fetchArticleDetails( array_keys( $articleIds ) ); foreach ( $rows as $row ) { foreach( $articleIds[$row['id']] as $id ) { unset( $row['id'] ); $data[$id] = array_merge( $data[$id], $row ); } } } return $data; }
public function processXmlFiles() { $xmlNames = array(); $remoteIds = array(); foreach ( $this->xmlFiles as $key => $xmlFile ) { $xmlNames[$key] = $xmlFile['name']; } if ( !empty( $xmlNames ) ) { $sql = "SELECT * FROM import_status s WHERE s.xml_file IN ('" . implode( "','" , $xmlNames ) . "') ORDER BY s.xml_file, s.version DESC"; $db = MMImportMonitorHelper::db(); $rows = $db->arrayQuery( $sql ); $keyMap = array_flip( $xmlNames ); foreach ( $rows as $row ) { $key = $keyMap[$row['xml_file']]; if ( !isset( $this->xmlFiles[$key] ) ) { $this->xmlFiles[$key] = array( 'status' => array() ); } $this->xmlFiles[$key]['status'][] = $row; if ( !empty( $row['remote_id'] ) ) { if ( !isset( $remoteIds[$row['remote_id']] ) ) { $remoteIds[$row['remote_id']] = array(); } $remoteIds[$row['remote_id']][] = array( 'key' => $key, 'index' => count( $this->xmlFiles[$key]['status'] ) - 1 ); } } $ids = ImportStatus::fetchObjectAndNodeIds( array_keys( $remoteIds ) ); foreach ( $ids as $id ) { foreach ( $remoteIds[$id['remote_id']] as $target ) { $this->xmlFiles[$target['key']]['status'][$target['index']]['object_id'] = $id['id']; $this->xmlFiles[$target['key']]['status'][$target['index']]['node_id'] = $id['main_node_id']; } } } $this->isXmlProcessed = true; }