/**
     *
     * @return eZDBInterface
     */
    public static function db() {
        if (!self::$db) {
            $ini = eZIni::instance('sqliimport.ini');
            $databaseImplementation = $ini->variable( 'DatabaseSettings', 'DatabaseImplementation' );
            list( $server, $port, $user, $pwd, $db, $usePersistentConnection) = $ini->variableMulti( 'DatabaseSettings', array( 'Server', 'Port', 'User', 'Password', 'Database', 'UsePersistentConnection', ) );
            $databaseParameters = array(
                'server' => $server,
                'port' => $port,
                'user' => $user,
                'password' => $pwd,
                'database' => $db,
                'use_persistent_connection' => $usePersistentConnection
            );

            self::$db = eZDB::instance($databaseImplementation, $databaseParameters, true);
        }

        return self::$db;
    }
Ejemplo n.º 2
0
<?php

$module = $Params['Module'];
$namedParameters = $module->getNamedParameters();
$statusId = $namedParameters['id'];

$ini = eZIni::instance('merck.ini');
$db = MMImportMonitorHelper::db();
$sql = '
    SELECT st.date as st_date, st.xml_file as st_xml_file, c.publisher_folder_id as c_publisher_folder_id
    FROM import_status as st
    LEFT JOIN article as a ON a.id = st.article_id
    LEFT JOIN content as c ON a.content_id = c.id
    LEFT JOIN publisher_folder as p ON c.publisher_folder_id = p.id
    WHERE st.id = "%s";
';
$row = reset($db->arrayQuery(sprintf($sql, $db->escapeString($statusId))));

if ( !empty( $row  ) ) {
    $sql = "SELECT p.path as p_path FROM mm_publisher_folder WHERE p.id={$row['c_publisher_folder_id']}";
    $publisherRow = reset( MMDB::instance()->arrayQuery( $sql ) );
    $row['p_path'] = ( empty( $publisherRow ) ? null : $publisherRow['p_path'] );

    $pathPrefix = $ini->variable('ImportMonitor', 'XmlFilePath');
    $path = sprintf('%s/%s/archived/%s_%s', $pathPrefix, $row['p_path'], date('Ymd', $row['st_date']), $row['st_xml_file']);

    if (!empty($row['p_path']) && file_exists($path)) {
        header ("Content-Type:text/xml");
        echo file_get_contents($path);
    }
}
    public static function getArticleMedias( $articleId )
    {
        $mediaTableNames = array(
            'image',
            'video',
            'audio',
            'pdf'
        );
        $articleId = (integer)$articleId;
        $result = array();
        if ( !empty( $articleId ) )
        {
            $db = MMImportMonitorHelper::db();
            $joinQueryPart = "LEFT JOIN article a ON a.content_id=t.content_id";
            $whereQueryPart = "WHERE a.id='{$articleId}'";
            foreach ( $mediaTableNames as $tableName )
            {
                $sql = "SELECT * FROM {$tableName} t {$joinQueryPart} {$whereQueryPart}";
                $result[$tableName] = $db->arrayQuery( $sql );
            }
        }

        return $result;
    }
Ejemplo n.º 4
0
if ( !( $xmlFile && $archiveFilename && $archiveContext ) )
{
    return $module->handleError( eZError::KERNEL_NOT_FOUND );
}

$archive = MMImportMonotorArchive::instance( $archiveContext );

if ( !( $archive instanceof MMImportMonotorArchive ) )
{
    return $module->handleError( eZError::KERNEL_NOT_FOUND );
}

$cmd = 'unzip -o "' . $archive->getPath() . '/' . $archiveFilename . '" "' . $xmlFile . '" -d /tmp';
exec( $cmd, $output );

$filename = "/tmp/$xmlFile";
$xml = file_get_contents( $filename );

if ( preg_match( '/\/.*([a-f0-9]{32}_.+\.xml)$/', $xmlFile, $matches ) )
{
    $xmlFile = $matches[1];
}
$xmlDetails = MMImportMonitorHelper::getXmlDetails( $xmlFile );
$tpl->setVariable( 'xml', $xml );
$tpl->setVariable( 'xml_details', $xmlDetails );

$Result['content'] = $tpl->fetch( 'design:importmonitor/xmlfile.tpl' );
$Result['path'] = array(
    array('url' => '/monitor/dashboard', 'text' => 'Dashboard'),
    array('url' => false, 'text' => 'XML file'),
);
Ejemplo n.º 5
0
    public static function getXmlFilenames( $ids )
    {
        $sql = "SELECT DISTINCT s.xml_file FROM import_status s WHERE s.id IN ('%s')";
        $db = MMImportMonitorHelper::db();
        $sql = sprintf( $sql, implode( "','", $ids ) );
        $result = array();
        $rows = $db->arrayQuery( $sql );
        foreach ( $rows as $row )
        {
            $result[] = $row['xml_file'];
        }

        return $result;
    }
    public static function status( $args ) {
        $dbModel = MMImportMonitorHelper::db();
        $dbEz = eZDB::instance();

        $aSort = isset( $args[2] ) ? $args[2] : 'st_id';

        $offset = isset( $args[0] ) ? $args[0] : 0;
        $limit = isset( $args[1] ) ? $args[1] : 25;
        $order = isset( $args[3] ) && $args[3] == 'desc' ? 'desc' : 'asc';
        $sort = array($aSort . ' ' . $order);

        $result = array(
            'recordsReturned' => 0,
            'totalRecords' => 0,
            'startIndex' => 0,
            'pageSize' => 0,
            'sort' => $aSort,
            'dir' => $order,
            'records' => array(),
        );

        // Select SQL alias
        $fieldsMap = array(
            'a_id' => 'a.id',
            'a_language' => 'a.language',
            'c_id' => 'c.id',
            'st_id' => 'st.id',
            'st_remote_id' => 'st.remote_id',
            'st_version' => 'st.version',
            'st_date' => 'st.date',
            'st_xml_file' => 'st.xml_file',
            'st_xml_mdd' => 'st.status_xml_mdd',
            'st_mdd_ez' => 'st.status_mdd_ez',
            'st_warning' => 'st.warning_messages',
            'st_error' => 'st.error_messages',
            'st_origin' => 'st.origin'
        );

        // Parse filter
        $filters = array();
        $_filters = array_slice($args, 4);
        foreach($_filters as $filter) {
            $params = explode(':', $filter);
            $filters[$params[0]] = $params[1];
        }

        $where = array('article_id IS NOT NULL');

        //////////
        // Filter on object ID and Node ID
        //////////
        $contentObjectWhere = array();
        foreach($filters as $key => $value) {
            if ($key == 'o_id') {
                $contentObjectWhere[] = sprintf("object.id = '%s'", $dbModel->escapeString($value));
            } elseif ($key == 'n_id') {
                $contentObjectWhere[] = sprintf("tree.node_id = '%s'", $dbModel->escapeString($value));
            }
        }

        if (count($contentObjectWhere)) {
            if ($aSort != 'a_id') $sort[] = 'a_id ASC';

            $sqlPattern = '
                SELECT DISTINCT object.remote_id
                FROM ezcontentobject as object
                LEFT JOIN ezcontentobject_tree as tree on object.id = tree.contentobject_id
                WHERE %s;
            ';

            $sql = sprintf($sqlPattern, implode(' AND ', $contentObjectWhere));
            $rows = $dbEz->arrayQuery($sql);
            $remoteIds = array();

            while(list(,$row) = each($rows)) {
                $remoteIds[] = $row['remote_id'];
            }

            if (count($remoteIds)) {
                $where[] = sprintf("st.remote_id IN ('%s')", implode("','", $remoteIds));
            } else {
                return $result;
            }
        }

        //////////
        // Filter on columns of import_status table
        //////////

        // Create SQL Where part
        foreach($filters as $key => $value) {
            if (isset($fieldsMap[$key])) {
                $where[] = sprintf("%s = '%s'", $fieldsMap[$key], $dbModel->escapeString($value));
            }
        }

        // Subquery to get last version
        if (isset($filters['last_version']) && $filters['last_version'] == '1') {
            $from = '
                SELECT article_id, MAX(VERSION) as version
                FROM import_status
                WHERE article_id IS NOT NULL
                GROUP BY article_id
            ';

            $sqlPattern = '
                SELECT %s
                FROM (' . $from . ') as st_last
                INNER JOIN import_status as st USING (article_id, version)
                LEFT JOIN article as a ON a.id = st.article_id
                LEFT JOIN content as c ON a.content_id = c.id
                WHERE %s
            ';

        } else {
            $sqlPattern = '
                SELECT %s
                FROM import_status as st
                LEFT JOIN article as a ON a.id = st.article_id
                LEFT JOIN content as c ON a.content_id = c.id
                WHERE %s
            ';
        }
        if ($aSort != 'st_version') $sort[] = 'st_version DESC';



        // Create SQL select part
        $selectFields = array();
        foreach($fieldsMap as $alias => $column) {
            $selectFields[] = sprintf('%s as %s', $column, $alias);
        }

        // Create complete SQL
        $sql = sprintf(
                $sqlPattern . ' ORDER BY %s LIMIT %d, %d',
                implode(', ', $selectFields),
                implode(' AND ', $where),
                implode(', ', $sort),
                $offset, $limit
        );
        $rows = $dbModel->arrayQuery($sql);

        // Transform to associative array
        $records = array();
        $remoteIds = array();
        while(list(,$record) = each($rows)) {
            $records[] = array_merge($record, array('o_id' => null, 'n_id' => null));
            $remoteIds[] = $record['st_remote_id'];
        }
        unset($rows);


        // Get total count
        $selectFields = array('COUNT(*) as count');
        $sql = sprintf($sqlPattern, implode(', ', $selectFields),  implode(' AND ', $where));
        $rows = $dbModel->arrayQuery($sql);
        $count = $rows[0]['count'];


        // Get object_id and main_node_id
        $sqlPattern = '
            SELECT object.remote_id, object.id, tree.main_node_id
            FROM ezcontentobject as object
            LEFT JOIN ezcontentobject_tree as tree on object.id = tree.contentobject_id
            WHERE object.remote_id IN (\'%s\')
            GROUP BY object.id;
        ';
        $sql = sprintf($sqlPattern, implode("', '", array_unique($remoteIds)));
        $mainNodeIDs = $dbEz->arrayQuery($sql);

        $ezIdsByRemoteId = array();
        while(list(,$row) = each($mainNodeIDs)) {
            $ezIdsByRemoteId[$row['remote_id']] = array('o_id' => $row['id'], 'n_id' => $row['main_node_id']);
        }

        // Complete records with object_id and main_node_id
        reset($records);
        while(list($key, $row) = each($records)) {
            $records[$key] = ( isset( $ezIdsByRemoteId[$row['st_remote_id']] ) ? array_merge($row, $ezIdsByRemoteId[$row['st_remote_id']]) : $row );
        }
        $result['recordsReturned'] = count($records);
        $result['totalRecords'] = (int) $count;
        $result['startIndex'] = (int) $offset;
        $result['pageSize'] = (int) $result['recordsReturned'];
        $result['sort'] = $aSort;
        $result['dir'] = $order;
        $result['records'] = array_values($records);

        return $result;
    }