$warning = $t->_('The database already contains %d tables.', $count); } } $installer_apps = new waInstallerApps(); if (extension_loaded('mysqli')) { $db_options['type'] = 'mysqli'; } else { $db_options['type'] = 'mysql'; } if (strpos($db_options['host'], ':')) { $db_options['port'] = ''; list($db_options['host'], $db_options['port']) = explode(':', $db_options['host'], 2); } $installer_apps->updateDbConfig($db_options); mysql_close($link); $installer_apps->setGenericOptions($_POST['config']); $checked = true; } else { $error_text = mysql_error($link); $error_no = mysql_errno($link); throw new Exception($t->_('Failed to connect to the "%s" database. (%s)', $db_options['database'], "#{$error_no}: {$error_text}")); } } else { $error_text = htmlentities(mysql_error(), ENT_QUOTES, 'utf-8'); $error_no = mysql_errno(); throw new Exception($t->_('Failed to connect to "%s" MySQL database server. (%s)', $db_options['host'], "#{$error_no}: {$error_text}")); } } catch (Exception $e) { if (!empty($link) && is_resource($link)) { mysql_close($link); }
private function downloadStandard($source, $temporary_path) { $source_stream = null; $target_stream = null; $md5 = null; try { $this->writeLog(__METHOD__ . ' :download via fopen', self::LOG_TRACE); /** * @var integer describe download file size */ $content_length = 0; $target = null; //TODO calculate estimated time / speed //TODO allow resume downloading $name = md5(preg_replace('/(\\?.*$)/', '', $source)); $default_socket_timeout = @ini_set('default_socket_timeout', self::TIMEOUT_SOCKET); //TODO use file_exists for local sources $source_stream = @fopen($source, 'r'); @ini_set('default_socket_timeout', $default_socket_timeout); if (!$source_stream) { $hint = 'for details see update log;'; if (preg_match('@^([a-z\\.]+)://@', $source, $matches)) { $wrappers = stream_get_wrappers(); if (!in_array($matches[1], $wrappers)) { $hint .= " Stream {$matches[1]} not supported;"; } } if (preg_match('@^https?://@', $source) && !ini_get('allow_url_fopen')) { $hint .= " PHP ini option 'allow_url_fopen' are disabled;"; } if (!empty($http_response_header)) { foreach ($http_response_header as $header) { if (preg_match('@^status:\\s+(\\d+)\\s+(.+)$@i', $header, $matches)) { $hint .= " {$matches[1]} {$matches[2]}"; $hint .= self::getHintByStatus($matches[1]); break; } } } throw new Exception("Error while opening source stream [{$source}]. Hint: {$hint}"); } elseif (!empty($http_response_header)) { //XXX ???? foreach ($http_response_header as $header) { $this->writeLog(__METHOD__, self::LOG_DEBUG, $header); if (preg_match('@^X-license:\\s+(\\w+)$@i', $header, $matches)) { waInstallerApps::setGenericOptions(array('license_key' => $matches[1])); } elseif (preg_match('@^Content-MD5:\\s+(.+)$@i', $header, $matches)) { if (preg_match('@^[0-9A-F]{32}$@', $matches[1])) { $md5 = strtolower($matches[1]); } elseif ($matches = unpack('H*', base64_decode($matches[1]))) { if (preg_match('@^[0-9A-F]{32}$@i', $matches[1])) { $md5 = strtolower($matches[1]); } } } } } $this->setState(); if (stream_is_local($source_stream)) { fclose($source_stream); $target = $source; $this->writeLog(__METHOD__ . ' :Source file is local', self::LOG_TRACE, $target); } else { //TODO check target path rights $target = self::formatPath(self::$root_path . $temporary_path . '/' . $name . ''); $this->mkdir($temporary_path); $target_stream = @fopen($target, 'wb'); if (!$target_stream) { throw new Exception("Error while write temporal download file {$target}"); } $this->writeLog(__METHOD__ . ' :Source file is distant', self::LOG_TRACE, array('source' => $source, 'target' => $target)); //{{Read source properties list($content_length, $download_content_length, $buf) = $this->getStreamInfo($source_stream); //}}Read source properties $this->setState(array('stage_value' => $content_length, 'stage_current_value' => $download_content_length)); if ($buf) { fwrite($target_stream, $buf); } $download_chunk_size = max($content_length ? ceil($content_length / 10240000) * 102400 : 102400, 102400); $retry_counter = 0; while (($delta = stream_copy_to_stream($source_stream, $target_stream, $download_chunk_size)) || $content_length && $download_content_length < $content_length && ++$retry_counter < 20 || !$content_length && ++$retry_counter < 3) { if ($delta) { $download_content_length += $delta; if ($retry_counter) { $this->writeLog(__METHOD__ . ' complete server data transfer', self::LOG_TRACE, compact('content_length', 'download_content_length', 'retry_counter', 'delta')); $retry_counter = 0; } } else { $this->writeLog(__METHOD__ . ' wait server data transfer', self::LOG_TRACE, compact('content_length', 'download_content_length', 'retry_counter', 'delta')); sleep(3); } $performance = $this->setState(array('stage_current_value' => $download_content_length, 'debug' => $download_chunk_size)); //adjust download chunk size //MAX = 8Mb/s MIN = 100Kb/s step 10Kb $download_chunk_size = $this->adjustStageChunk($download_chunk_size, $performance, __FUNCTION__, 10240, 102400, 8388608); } fclose($source_stream); fclose($target_stream); } return array($target, $content_length, $md5); } catch (Exception $ex) { //write state and error message if ($source_stream && is_resource($source_stream)) { fclose($source_stream); } if ($target_stream && is_resource($target_stream)) { fclose($target_stream); } throw $ex; } }