load_config(); if (!empty($_POST['dm_key']) && ($_POST['dm_key']==$me->dm_key)) { $connection = $me->getConnection($_POST['dblayer']); if ($connection==null) { addError(l10n('unknown dblayer')); } else { $dblayer = $_POST['dblayer']; include_once PHPWG_ROOT_PATH . 'include/dblayer/functions_'.$dblayer.'.inc.php'; $pwg_db_link = pwg_db_connect($connection['db_host'], $connection['db_user'], $connection['db_password'], $connection['db_base']); $result = execute_sqlfile(PHPWG_ROOT_PATH.'install/piwigo_structure-'.$dblayer.'.sql', 'piwigo_', $connection['prefix']); if (!$result) { addError(l10n('Cannot create struture')); } else { $structure_file = PHPWG_ROOT_PATH .'/install/piwigo_structure-mysql.sql'; $content = file_get_contents($structure_file); $pattern = '!CREATE TABLE `([^`]*)`!'; preg_match_all($pattern, $content, $matches); $Tables = $matches[1]; $ignoreTables = array('piwigo_history', 'piwigo_history_summary', 'piwigo_sessions', 'piwigo_user_cache', 'piwigo_user_cache_categories'); $dump_dir = $conf['local_data_dir'].'/plugins/database_migration/'; foreach ($Tables as $table) { if (in_array($table, $ignoreTables)) { continue; } $result = execute_sqlfile("{$dump_dir}/{$table}.dump", 'piwigo_', $connection['prefix']); if (!$result) { addError(l10n(sprintf('Cannot import %s content', $table))); break; } } } } } else { addError(l10n('Hacking attempt!')); } if (empty($response)) { addInfo(l10n('Import completed')); } if ($xmlhttprequest) { header("Content-Type: application/json"); echo json_encode($response); exit(); } else { echo '
', print_r($response, true), ''; } function addError($message) { global $response; $response['error'] = $message; } function addInfo($message) { global $response; $response['info'] = $message; } function execute_sqlfile($filepath, $replaced, $replacing) { $sql_lines = file($filepath); $query = ''; foreach ($sql_lines as $sql_line) { $sql_line = trim($sql_line); if (preg_match('/(^--|^$)/', $sql_line)) { continue; } $query.= ' '.$sql_line; if (preg_match('/;$/', $sql_line)) { $query = trim($query); $query = str_replace($replaced, $replacing, $query); $result = pwg_query($query); $query = ''; } } return true; } ?>