/** * Update Hawk */ public function updateHawk() { try { $api = new HawkApi(); $nextVersions = $api->getCoreAvailableUpdates(); if (empty($nextVersions)) { throw new \Exception("No newer version is available for Hawk"); } // Update incrementally all newer versions foreach ($nextVersions as $version) { // Download the update archive $archive = $api->getCoreUpdateArchive($version['version']); // Extract the downloaded file $zip = new \ZipArchive(); if ($zip->open($archive) !== true) { throw new \Exception('Impossible to open the zip archive'); } $zip->extractTo(TMP_DIR); // Put all modified or added files in the right folder $folder = TMP_DIR . 'update-v' . $version['version'] . '/'; App::fs()->copy($folder . 'to-update/*', ROOT_DIR); // Delete the files to delete $toDeleteFiles = explode(PHP_EOL, file_get_contents($folder . 'to-delete.txt')); foreach ($toDeleteFiles as $file) { if (is_file(ROOT_DIR . $file)) { unlink(ROOT_DIR . $file); } } // Remove temporary files and folders App::fs()->remove($folder); App::fs()->remove($archive); } // Execute the update method if exist $updater = new HawkUpdater(); $methods = get_class_methods($updater); foreach ($nextVersions as $version) { $method = 'v' . str_replace('.', '_', $version['version']); if (method_exists($updater, $method)) { $updater->{$method}(); } } App::cache()->clear('views'); App::cache()->clear('lang'); App::cache()->clear(Autoload::CACHE_FILE); App::cache()->clear(Lang::ORIGIN_CACHE_FILE); $response = array('status' => true); } catch (\Exception $e) { $response = array('status' => false, 'message' => DEBUG_MODE ? $e->getMessage() : Lang::get('admin.update-hawk-error')); } App::response()->setContentType('json'); return $response; }