public function update() { $this->config->set('MODULE_STATS_UPDATED', null); $this->config->save(); $response = new JSONResponse(''); $updatePath = $this->getRepoResponse('package/updatePath', array('from' => $this->request->get('from'), 'to' => $this->request->get('to'))); $flush = array('path' => $updatePath); $flush['status'] = $this->translate($updatePath ? '_status_fetch' : '_status_nothing_to_fetch'); $response->flushChunk($flush); if (!$updatePath) { return $response; } require_once ClassLoader::getRealPath('library.pclzip') . '/pclzip.lib.php'; // process update $module = $this->application->getConfigContainer()->getModule($this->request->get('id')); foreach ($updatePath as $key => $package) { $tmpFile = ClassLoader::getRealPath('cache.') . 'update' . rand(1, 5000000) . '.zip'; $tmpDir = substr($tmpFile, 0, -4); $response->flushChunk(array('package' => $package, 'status' => $this->translate('_status_fetch'))); file_put_contents($tmpFile, $this->getRepoResponse('package/download', $package, true)); $archive = new PclZip($tmpFile); mkdir($tmpDir); $archive->extract($tmpDir); unlink($tmpFile); $res = $module->applyUpdate($tmpDir); if ($res === true) { $response->flushChunk(array('status' => 'ok')); } else { $errs = array('_err_update_copy_msg', '_err_update_db', '_err_update_custom'); $response->flushChunk(array('status' => 'err', 'msg' => $this->maketext($errs[$res[0]], array($res[1])))); $res = false; } $this->application->rmdir_recurse($tmpDir); if (!$res) { return; } } $response->flushChunk(array('final' => $this->makeText('_update_complete', array($this->translate($module->getName()))))); }