1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
<?php /* * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2008 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ if (!defined('G2_SUPPORT')) { return; }
/** * Gallery Database Import * @package Support */
$g2Base = dirname(dirname(dirname(__FILE__))) . '/'; require_once($g2Base . 'modules/core/classes/GalleryCoreApi.class'); require_once($g2Base . 'modules/core/classes/GalleryStorage.class'); require_once($g2Base . 'modules/core/classes/GalleryUtilities.class'); require_once($g2Base . 'lib/support/SupportStatusTemplate.class');
$templateData = array();
$template = new SupportStatusTemplate('Database Import');
$configFilePath = (defined('GALLERY_CONFIG_DIR') ? GALLERY_CONFIG_DIR . '/' : $g2Base) . 'config.php';
require_once(dirname(__FILE__) . '/../../embed.php');
$templateData = array(); $templateData['bodyFile'] = 'ImportRequest.html'; $renderFullPage = true;
$ret = GalleryEmbed::init(array('fullInit' => 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); } ?>
|