|
16 | 16 |
|
17 | 17 | namespace phpMyFAQ\Setup;
|
18 | 18 |
|
19 |
| -use JsonException; |
20 | 19 | use Monolog\Level;
|
21 | 20 | use phpMyFAQ\Configuration;
|
22 | 21 | use phpMyFAQ\Setup;
|
|
26 | 25 | use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
27 | 26 | use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
28 | 27 | use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
29 |
| -use ZipArchive; |
| 28 | +use PhpZip\ZipFile; |
| 29 | +use PhpZip\Exception\ZipException; |
30 | 30 |
|
31 | 31 | class Upgrade extends Setup
|
32 | 32 | {
|
@@ -129,8 +129,8 @@ public function downloadPackage(string $version): string|bool
|
129 | 129 | *
|
130 | 130 | * @return bool
|
131 | 131 | * @throws TransportExceptionInterface|ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|JsonException
|
132 |
| - * @var string $path | Path to zip file |
133 |
| - * @var string $version | Version to verify |
| 132 | + * @param string $path | Path to zip file |
| 133 | + * @param string $version | Version to verify |
134 | 134 | */
|
135 | 135 | public function verifyPackage(string $path, string $version): bool
|
136 | 136 | {
|
@@ -163,34 +163,67 @@ public function verifyPackage(string $path, string $version): bool
|
163 | 163 | * Method to unpack the downloaded phpMyFAQ package
|
164 | 164 | *
|
165 | 165 | * @return bool
|
166 |
| - * @var string $path Path of the package |
| 166 | + * @param string $path | Path of the package |
| 167 | + * @throws ZipException |
167 | 168 | */
|
168 | 169 | public function unpackPackage(string $path): bool
|
169 | 170 | {
|
170 |
| - $zip = new ZipArchive(); |
171 |
| - if (!$zip->open($path)) { |
172 |
| - $this->configuration->getLogger()->log(Level::Error, $zip->getStatusString()); |
| 171 | + $zip = new ZipFile(); |
| 172 | + try { |
| 173 | + if (!is_file($path)) { |
| 174 | + return false; |
| 175 | + } else { |
| 176 | + $zip->openFile($path); |
| 177 | + $zip->extractTo(PMF_CONTENT_DIR . '/upgrades/'); |
| 178 | + $zip->close(); |
| 179 | + return true; |
| 180 | + } |
| 181 | + } catch (ZipException $e) { |
| 182 | + $this->configuration->getLogger()->log(Level::Error, $e->getMessage()); |
173 | 183 |
|
174 | 184 | return false;
|
175 |
| - } else { |
176 |
| - if (!$zip->extractTo(PMF_CONTENT_DIR . '/upgrades/')) { |
177 |
| - $this->configuration->getLogger()->log(Level::Error, $zip->getStatusString()); |
| 185 | + } |
| 186 | + } |
178 | 187 |
|
| 188 | + /** |
| 189 | + * Method to create a temporary backup of the current files |
| 190 | + * |
| 191 | + * @param string $backupName | Name of the created backup |
| 192 | + * @return bool |
| 193 | + * @throws ZipException |
| 194 | + */ |
| 195 | + public function createTemporaryBackup(string $backupName): bool |
| 196 | + { |
| 197 | + try { |
| 198 | + $zip = new ZipFile(); |
| 199 | + if (!is_file(PMF_CONTENT_DIR . '/upgrades/' . $backupName)) { |
| 200 | + $zip->addDirRecursive(PMF_ROOT_DIR); |
| 201 | + $zip->saveAsFile(PMF_CONTENT_DIR . '/upgrades/' . $backupName); |
| 202 | + $zip->close(); |
| 203 | + return true; |
| 204 | + } else { |
179 | 205 | return false;
|
180 | 206 | }
|
181 |
| - $zip->close(); |
| 207 | + } catch (ZipException $e) { |
| 208 | + $this->configuration->getLogger()->log(Level::Error, $e->getMessage()); |
182 | 209 |
|
183 |
| - return true; |
| 210 | + return false; |
184 | 211 | }
|
185 | 212 | }
|
186 | 213 |
|
187 |
| - /** |
188 |
| - * Method to create a temporary backup of the current files |
| 214 | + /** |
| 215 | + * Method to delete the temporary created backup. |
189 | 216 | *
|
190 |
| - * @return void |
| 217 | + * @param string $backupName | Name of the created backup |
| 218 | + * @return bool |
191 | 219 | */
|
192 |
| - public function createTemporaryBackup() |
| 220 | + public function deleteTemporaryBackup(string $backupName): bool |
193 | 221 | {
|
| 222 | + if (is_file(PMF_CONTENT_DIR . '/upgrades/' . $backupName)) { |
| 223 | + return unlink(PMF_CONTENT_DIR . '/upgrades/' . $backupName); |
| 224 | + } else { |
| 225 | + return false; |
| 226 | + } |
194 | 227 | }
|
195 | 228 |
|
196 | 229 | /**
|
|
0 commit comments