$value) { if (preg_match('/_TABLE$/', $constant)) { $dumper->getTableStructure($value); if ($constant == 'HISTORY_TABLE' and !isset($_POST['includeHistory'])) { continue; } $dumper->getTableData($value); } } } if (@filesize($backupFile)) { $http_headers = array( 'Content-Length: '.@filesize($backupFile), 'Content-Type: text/x-sql', 'Content-Disposition: attachment; filename="database.sql";', 'Content-Transfer-Encoding: binary', ); foreach ($http_headers as $header) { header($header); } @readfile($backupFile); autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); exit(); } else { array_push($page['errors'], l10n('Unable to dump database.')); } } function autoupdate_upgrade_to($upgrade_to, &$step) { global $page, $conf, $template; if (!version_compare($_POST['upgrade_to'], PHPWG_VERSION, '>')) { redirect(get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))); } if ($step == 2) { preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches); $code = $matches[1].'.x_to_'.$_POST['upgrade_to']; $dl_code = str_replace(array('.', '_'), '', $code); $remove_path = $code; $obsolete_list = 'obsolete.list'; } else { $code = $_POST['upgrade_to']; $dl_code = $code; $remove_path = version_compare($code, '2.0.8', '>=') ? 'piwigo' : 'piwigo-'.$code; $obsolete_list = PHPWG_ROOT_PATH.'install/obsolete.list'; } if (empty($page['errors'])) { $path = $conf['local_data_dir'].'/autoupdate'; $filename = $path.'/'.$code.'.zip'; @mkgetdir($path); $chunk_num = 0; $end = false; $zip = @fopen($filename, 'w'); while (!$end) { $chunk_num++; if (@fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.$dl_code.'&chunk_num='.$chunk_num, $result) and $input = @unserialize($result)) { if (0 == $input['remaining']) { $end = true; } @fwrite($zip, base64_decode($input['data'])); } else { $end = true; } } @fclose($zip); if (@filesize($filename)) { $zip = new PclZip($filename); if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_SET_CHMOD, 0755, PCLZIP_OPT_REPLACE_NEWER)) { //Check if all files were extracted $error = ''; foreach($result as $extract) { if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory'))) { // Try to change chmod and extract if (@chmod(PHPWG_ROOT_PATH.$extract['filename'], 0777) and ($res = $zip->extract(PCLZIP_OPT_BY_NAME, $remove_path.'/'.$extract['filename'], PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_SET_CHMOD, 0755, PCLZIP_OPT_REPLACE_NEWER)) and isset($res[0]['status']) and $res[0]['status'] == 'ok') { continue; } else { $error .= $extract['filename'].': '.$extract['status']."\n"; } } } if (empty($error)) { process_obsolete_list($obsolete_list); autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); invalidate_user_cache(true); $template->delete_compiled_templates(); unset($_SESSION['need_update']); if ($step == 2) { array_push($page['infos'], sprintf(l10n('autoupdate_success'), $upgrade_to)); $step = -1; } else { redirect(PHPWG_ROOT_PATH.'upgrade.php?now='); } } else { file_put_contents($conf['local_data_dir'].'/autoupdate/log_error.txt', $error); $relative_path = trim(str_replace(dirname(dirname(dirname(dirname(__FILE__)))), '', $conf['local_data_dir']), '/\\'); array_push($page['errors'], sprintf(l10n('autoupdate_extract_fail'), PHPWG_ROOT_PATH.$relative_path.'/autoupdate/log_error.txt')); } } else { autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); array_push($page['errors'], l10n('autoupdate_fail')); } } else { array_push($page['errors'], l10n('Piwigo cannot retrieve upgrade file from server')); } } } define('AU_DEFAULT_INDEX', file_get_contents(AUTOUPDATE_PATH.'index.php')); ?>