/** * Update lynxpress * * @access private */ private function update() { if (VPost::update()) { try { if (Helper::check_update() === false) { throw new Exception('No update available!'); } //make a backup of the database first, with an email sent to webmaster with the whole dump $bk = new Backup(); $bk->save('backup/dump-' . date('Y-m-d-H:i:s') . '.sql'); $html = new File(); $html->_content = '<!--The Lynx is not here!-->'; $html->save('backup/index.html'); $mail = new Mail(WS_EMAIL, 'Databse dump made before update at ' . date('Y-m-d H:i:s'), $bk->_sql); $mail->send(); //end backup //retrieve json manifest from the server $manifest = new Curl('http://update.lynxpress.org/manifest.json'); $manifest = json_decode($manifest->_content, true); //retrieve zip with all files inside $curl_zip = new Curl('http://versions.lynxpress.org/Lynxpress-' . $manifest['version'] . '.zip'); if ($curl_zip->_content == '<!--The Lynx is not here!-->') { throw new Exception('Can\'t retrieve lynxpress archive'); } $zip = new File(); $zip->_content = $curl_zip->_content; $zip->save('tmp/update.zip'); unset($zip); unset($curl_zip); File::unzip('tmp/update.zip', 'tmp/update/'); File::delete('tmp/update.zip'); //check if all files are readable foreach ($manifest['src'] as $src) { File::read('tmp/update/Lynxpress-' . $manifest['version'] . '/' . $src); } //replace all files registered in the manifest foreach ($manifest['src'] as $key => $src) { File::read('tmp/update/Lynxpress-' . $manifest['version'] . '/' . $src)->save($manifest['dest'][$key]); File::delete('tmp/update/Lynxpress-' . $manifest['version'] . '/' . $src); } //execute special queries foreach ($manifest['queries'] as $query) { $this->_db->query(str_replace('{{prefix}}', DB_PREFIX, $query)); } //remove files foreach ($manifest['remove'] as $file) { File::delete($file, false); } $config = File::read(PATH . 'config.php'); $config->_content = str_replace('(\'WS_VERSION\', \'' . WS_VERSION . '\')', '(\'WS_VERSION\', \'' . $manifest['version'] . '\')', $config->_content); $config->save(); unset($config); $config = File::read(PATH . 'config.sample.php'); $config->_content = str_replace('(\'WS_VERSION\', \'' . WS_VERSION . '\')', '(\'WS_VERSION\', \'' . $manifest['version'] . '\')', $config->_content); $config->save(); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::ws_update($result); } }