コード例 #1
0
ファイル: xml_dump.php プロジェクト: erico-deh/ocPortal
<?php

/*
 ocPortal
 Copyright (c) ocProducts, 2004-2012
 See text/EN/licence.txt for full licencing information.
 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
disable_php_memory_limit();
$GLOBALS['NO_DB_SCOPE_CHECK'] = true;
$filename = 'ocportal-' . get_site_name() . '.' . date('Y-m-d') . '.sql';
if (!isset($_GET['testing'])) {
    header('Content-Type: application/octet-stream' . '; authoritative=true;');
    if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) {
        header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"');
    } else {
        header('Content-Disposition: attachment; filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"');
    }
} else {
    header('Content-type: text/plain');
}
require_code('xml_dump');
$st = get_sql_dump();
foreach ($st as $s) {
    echo $s;
    echo "\n\n";
}
$GLOBALS['SCREEN_TEMPLATE_CALLED'] = '';
exit;
コード例 #2
0
if (isset($_REQUEST["search_path"])) {
    $search_path = $_REQUEST["search_path"];
}
if (isset($_REQUEST["mask"])) {
    $mask = $_REQUEST["mask"];
}
if (isset($_REQUEST["ignore_dir"])) {
    $ignore_dir = $_REQUEST["ignore_dir"];
}
if (!isset($import_handle)) {
    $import_handle = "";
}
$package_size = 1048576;
switch ($task) {
    case "get_sql":
        get_sql_dump();
        break;
    case "get_sql_file":
        get_sql_file($filename, $position);
        break;
    case "put_sql":
        put_sql($import_handle);
        break;
    case "get_version":
        get_version($version);
        break;
    case "get_config":
        get_config();
        break;
    case "get_category_tree":
        get_category_tree();
コード例 #3
0
ファイル: xml_dump.php プロジェクト: erico-deh/ocPortal
/**
 * Script to handle XML DB/MySQL chain synching.
 */
function xml_dump_script()
{
    // Run checks and set up chain DB
    if (get_db_type() != 'xml') {
        warn_exit('It makes no sense to run this script if you are not running the XML database driver.');
    }
    global $SITE_INFO;
    if (array_key_exists('db_chain_type', $SITE_INFO)) {
        require_code('database/' . $SITE_INFO['db_chain_type']);
        $chain_db = new database_driver($SITE_INFO['db_chain'], $SITE_INFO['db_chain_host'], $SITE_INFO['db_chain_user'], $SITE_INFO['db_chain_password'], get_table_prefix(), false, object_factory('Database_Static_' . $SITE_INFO['db_chain_type']));
    } else {
        warn_exit('It makes no sense to run this script if you have not set up the following config options in info.php: db_chain_type, db_chain_host, db_chain_user, db_chain_password, db_chain');
    }
    $chain_connection =& $chain_db->connection_write;
    if (count($chain_connection) > 4) {
        $chain_connection = call_user_func_array(array($chain_db->static_ob, 'db_get_connection'), $chain_connection);
        _general_db_init();
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    $GLOBALS['DEBUG_MODE'] = false;
    $GLOBALS['SEMI_DEBUG_MODE'] = false;
    @ini_set('ocproducts.xss_detect', '0');
    if (strtolower(ocp_srv('REQUEST_METHOD')) == 'get') {
        $from = get_param('from', NULL);
        $skip = get_param('skip', NULL);
        $only = get_param('only', NULL);
        echo '
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<title>XML/MySQL DB syncher</title>
		</head>
		<body>
		';
        echo '<p>Select the tables to sync below. Tables have been auto-ticked based on what seems to need re-synching.</p>';
        $keep = symbol_tempcode('KEEP', array('1'));
        echo '<form title="Choose tables" method="post" action="' . escape_html(find_script('xml_db_import') . $keep->evaluate()) . '">';
        $tables = array_keys(find_all_tables($GLOBALS['SITE_DB']));
        $mysql_status = list_to_map('Name', $chain_db->query('SHOW TABLE STATUS'));
        $mysql_tables = array_keys($mysql_status);
        foreach ($tables as $table_name) {
            $default_selected = (!is_null($from) && $table_name >= $from || !is_null($only) && in_array($table_name, explode(',', $only))) && (!is_null($skip) || !in_array($table_name, explode(',', $skip)));
            $missing = !in_array(get_table_prefix() . $table_name, $mysql_tables);
            $count_mismatch = !$missing && $chain_db->query_value($table_name, 'COUNT(*)') != $GLOBALS['SITE_DB']->query_value($table_name, 'COUNT(*)');
            $date_mismatch = false;
            if (!$missing && !$count_mismatch) {
                $last_m_time = NULL;
                $path = get_custom_file_base() . '/uploads/website_specific/' . get_db_site() . '/' . get_table_prefix() . $table_name;
                $dh = @opendir($path);
                if ($dh !== false) {
                    while (($f = readdir($dh)) !== false) {
                        if (substr($f, -4) == '.dat' || substr($f, -4) == '.xml') {
                            $last_m_time = @max($last_m_time, filemtime($path . '/' . $f));
                        }
                        // @ because of the 255 read filepath limit on Windows
                    }
                    closedir($dh);
                }
                if (!is_null($last_m_time)) {
                    $mysql_time = strtotime($mysql_status[get_table_prefix() . $table_name]['Update_time']);
                    $date_mismatch = $mysql_time < $last_m_time;
                    // We can't do "!=" as last m-time for MySQL could well by the last sync time
                }
            }
            $needs_doing = $count_mismatch || $date_mismatch || $missing || $default_selected;
            echo '
				<div style="width: 500px">
					<span style="float: right; font-style: italic">
					' . ($missing ? '[table is missing]' : '') . '
					' . ($count_mismatch ? '[different record-counts]' : '') . '
					' . ($date_mismatch ? '[different last-modified-time]' : '') . '
					</span>

					<input ' . ($needs_doing ? 'checked="checked" ' : '') . 'type="checkbox" name="table_' . htmlentities($table_name) . '" id="table_' . htmlentities($table_name) . '" value="1" />
					<label for="table_' . htmlentities($table_name) . '">' . htmlentities($table_name) . '</label>
				</div>
			';
        }
        echo '<p><input type="submit" value="Sync" /> &nbsp;&nbsp;&nbsp;&nbsp; [<a href="#" onclick="var form=document.getElementsByTagName(\'form\')[0]; for (var i=0;i&lt;form.elements.length;i++) if (form.elements[i].checked) form.elements[i].checked=false; return false;">un-tick all</a>]</p>';
        echo '</form>';
        echo '
		</body>
		</html>
		';
        exit;
    }
    // Actualiser
    $from = NULL;
    $skip = NULL;
    $only = '';
    foreach (array_keys($_POST) as $key) {
        if (substr($key, 0, 6) == 'table_') {
            if ($only != '') {
                $only .= ',';
            }
            $only .= substr($key, 6);
        }
    }
    if ($only == '') {
        $only = NULL;
    }
    @header('Content-type: text/plain');
    @ob_end_clean();
    $sql = get_sql_dump(true, true, $from, is_null($skip) ? array() : explode(',', $skip), is_null($only) ? NULL : explode(',', $only));
    $cnt = count($sql);
    foreach ($sql as $i => $s) {
        print 'Executing query ' . strval($i + 1) . '/' . strval($cnt) . ' ... ' . $s . "\n\n";
        flush();
        $fail_ok = substr($s, 0, 5) == 'ALTER';
        $chain_db->static_ob->db_query($s, $chain_connection, NULL, NULL, $fail_ok, false);
    }
    print '!!Done!!';
}