false)); if ($ret) { $templateData['errors'][] = $ret->getAsHtml(); } else { $platform =& $gallery->getPlatform(); $storage =& $gallery->getStorage(); $templateData['warnings'] = array(); if (isset($_REQUEST['importDatabase'])) { $importFile = $_REQUEST['importFile']; /* Sanitize the input */ GalleryUtilities::sanitizeInputValues($importFile); if (!$platform->file_exists($importFile)) { return GalleryCoreApi::error(ERROR_BAD_PARAMETER, null, null, 'The file "' . $importFile . '" does not exist.'); } $verifiedFile = $_REQUEST['verifiedFile']; /* Sanitize the input */ GalleryUtilities::sanitizeInputValues($verifiedFile); $doImportFlag = true; if ($verifiedFile != $importFile) { $templateData['verifiedFile'] = $importFile; $verifiedFile = $importFile; $doImportFlag = verifyVersions($templateData, $importFile); } if ($doImportFlag) { $template->renderHeader(true); $template->renderStatusMessage('Restoring Gallery Database', '', 0); /* Do the database import */ $importer = $storage->getDatabaseImporter(); list ($ret, $errors) = $importer->importToDb($verifiedFile, 'importProgressCallback'); if ($ret) { $templateData['errors'][] = $ret->getAsHtml(); } else if ($errors != null) { if (!is_array($errors)) { $templateData['errors'][] = $errors->getAsHtml(); } else { foreach ($errors as $status) { $templateData['errors'][] = $status->getAsHtml(); } } } /* The import processing sets Gallery into maintenance mode, undo that now */ $ret = GalleryCoreApi::setMaintenanceMode(false); if ($ret) { $templateData['errors'][] = $ret->getAsHtml(); } $templateData['bodyFile'] = 'ImportFinished.html'; $templateData['hideStatusBlock'] = 1; $renderFullPage = false; } } else { getBackupFiles($templateData); /* Render the output */ $templateData['bodyFile'] = 'ImportRequest.html'; } } if (!$ret) { $ret = GalleryEmbed::done(); if ($ret) { $templateData['errors'][] = $ret->getAsHtml(); } } if ($renderFullPage) { $template->renderHeaderBodyAndFooter($templateData); } else { $template->renderBodyAndFooter($templateData); } /** * Verify the version compatibility and identify any modules that are incompatible with the * existing installation. * @param array $templateData The information to be displayed on the import page. * @param string $importFile The file to be verified. * @return boolean true if there are no verification messages to display. */ function verifyVersions(&$templateData, $importFile) { global $gallery; global $template; $storage =& $gallery->getStorage(); $importer = $storage->getDatabaseImporter(); $errors = $importer->verifyVersions($importFile); if (!empty($errors['warnings'])) { $templateData['versionWarnings'] = $errors['warnings']; } else { $templateData['versionWarnings'] = null; } if (!empty($errors['errors'])) { $templateData['errors'] = $errors['errors']; } else { $templateData['errors'] = null; } $verificationMessages = !empty($errors['warnings']) || !empty($errors['errors']); if ($verificationMessages) { getBackupFiles($templateData); /* Render the output */ $templateData['bodyFile'] = 'ImportRequest.html'; $templateData['hideStatusBlock'] = 1; } return !$verificationMessages; } /** * Retrieve the list of available backup files from the backup directory * @param array $templateData The information to be displayed on the import page. */ function getBackupFiles(&$templateData) { global $gallery; $platform =& $gallery->getPlatform(); $backupFiles = $gallery->getConfig('data.gallery.backup') . '*.xml'; $files = array(); foreach ($platform->glob($backupFiles) as $fileName) { $files[filectime($fileName) . $fileName] = $fileName; } krsort($files); $templateData['backupFiles'] = $files; if (count($files) == 0) { $templateData['errors'][] = 'There are no backups found. You will probably have to reinstall.'; } } /** * Update the progress bar with the current percent completion * @param float $percentage The current completion percentage. */ function importProgressCallback($percentage) { global $template; $template->renderStatusMessage('Importing Gallery Database', '', $percentage); } ?>