aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/setup.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-03-10 23:44:29 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-03-11 09:27:12 +0100
commit6c1a1234f8c5a064a72cb23cd397edcb9c6f0577 (patch)
tree531cc7f3dd6b70f6604f719828f7ba98c37dda63 /lib/private/setup.php
parent81fa9550a0e136421c1dacad3d26fdb19e9c63a3 (diff)
downloadnextcloud-server-6c1a1234f8c5a064a72cb23cd397edcb9c6f0577.tar.gz
nextcloud-server-6c1a1234f8c5a064a72cb23cd397edcb9c6f0577.zip
Properly handle available databases at runtime and respect setup checks in command line as well
Diffstat (limited to 'lib/private/setup.php')
-rw-r--r--lib/private/setup.php117
1 files changed, 102 insertions, 15 deletions
diff --git a/lib/private/setup.php b/lib/private/setup.php
index 064afecbfe8..1da42f0f8a4 100644
--- a/lib/private/setup.php
+++ b/lib/private/setup.php
@@ -8,19 +8,34 @@
namespace OC;
+use bantu\IniGetWrapper\IniGetWrapper;
use Exception;
-use OC_L10N;
use OCP\IConfig;
+use OCP\IL10N;
class Setup {
- /** @var IConfig */
+ /** @var \OCP\IConfig */
protected $config;
+ /** @var IniGetWrapper */
+ protected $iniWrapper;
+ /** @var IL10N */
+ protected $l10n;
+ /** @var \OC_Defaults */
+ protected $defaults;
/**
* @param IConfig $config
+ * @param IniGetWrapper $iniWrapper
+ * @param \OC_Defaults $defaults
*/
- function __construct(IConfig $config) {
+ function __construct(IConfig $config,
+ IniGetWrapper $iniWrapper,
+ IL10N $l10n,
+ \OC_Defaults $defaults) {
$this->config = $config;
+ $this->iniWrapper = $iniWrapper;
+ $this->l10n = $l10n;
+ $this->defaults = $defaults;
}
static $dbSetupClasses = array(
@@ -33,13 +48,6 @@ class Setup {
);
/**
- * @return OC_L10N
- */
- public static function getTrans(){
- return \OC::$server->getL10N('lib');
- }
-
- /**
* Wrapper around the "class_exists" PHP function to be able to mock it
* @param string $name
* @return bool
@@ -117,11 +125,90 @@ class Setup {
}
/**
+ * Gathers system information like database type and does
+ * a few system checks.
+ *
+ * @return array of system info, including an "errors" value
+ * in case of errors/warnings
+ */
+ public function getSystemInfo() {
+ $databases = $this->getSupportedDatabases();
+
+ $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data');
+
+ $errors = array();
+
+ // Create data directory to test whether the .htaccess works
+ // Notice that this is not necessarily the same data directory as the one
+ // that will effectively be used.
+ @mkdir($dataDir);
+ $htAccessWorking = true;
+ if (is_dir($dataDir) && is_writable($dataDir)) {
+ // Protect data directory here, so we can test if the protection is working
+ \OC\Setup::protectDataDirectory();
+
+ try {
+ $htAccessWorking = \OC_Util::isHtaccessWorking();
+ } catch (\OC\HintException $e) {
+ $errors[] = array(
+ 'error' => $e->getMessage(),
+ 'hint' => $e->getHint()
+ );
+ $htAccessWorking = false;
+ }
+ }
+
+ if (\OC_Util::runningOnMac()) {
+ $errors[] = array(
+ 'error' => $this->l10n->t(
+ 'Mac OS X is not supported and %s will not work properly on this platform. ' .
+ 'Use it at your own risk! ',
+ $this->defaults->getName()
+ ),
+ 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.')
+ );
+ }
+
+ if($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) {
+ $errors[] = array(
+ 'error' => $this->l10n->t(
+ 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' .
+ 'This will lead to problems with files over 4 GB and is highly discouraged.',
+ $this->defaults->getName()
+ ),
+ 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.')
+ );
+ }
+ if(!function_exists('curl_init') && PHP_INT_SIZE === 4) {
+ $errors[] = array(
+ 'error' => $this->l10n->t(
+ 'It seems that this %s instance is running on a 32-bit PHP environment and cURL is not installed. ' .
+ 'This will lead to problems with files over 4 GB and is highly discouraged.',
+ $this->defaults->getName()
+ ),
+ 'hint' => $this->l10n->t('Please install the cURL extension and restart your webserver.')
+ );
+ }
+
+ return array(
+ 'hasSQLite' => isset($databases['sqlite']),
+ 'hasMySQL' => isset($databases['mysql']),
+ 'hasPostgreSQL' => isset($databases['pgsql']),
+ 'hasOracle' => isset($databases['oci']),
+ 'hasMSSQL' => isset($databases['mssql']),
+ 'databases' => $databases,
+ 'directory' => $dataDir,
+ 'htaccessWorking' => $htAccessWorking,
+ 'errors' => $errors,
+ );
+ }
+
+ /**
* @param $options
* @return array
*/
- public static function install($options) {
- $l = self::getTrans();
+ public function install($options) {
+ $l = $this->l10n;
$error = array();
$dbType = $options['dbtype'];
@@ -146,7 +233,7 @@ class Setup {
$class = self::$dbSetupClasses[$dbType];
/** @var \OC\Setup\AbstractDatabase $dbSetup */
- $dbSetup = new $class(self::getTrans(), 'db_structure.xml');
+ $dbSetup = new $class($l, 'db_structure.xml');
$error = array_merge($error, $dbSetup->validate($options));
// validate the data directory
@@ -186,7 +273,7 @@ class Setup {
$secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
//write the config file
- \OC::$server->getConfig()->setSystemValues([
+ $this->config->setSystemValues([
'passwordsalt' => $salt,
'secret' => $secret,
'trusted_domains' => $trustedDomains,
@@ -281,7 +368,7 @@ class Setup {
* @throws \OC\HintException If .htaccess does not include the current version
*/
public static function updateHtaccess() {
- $setupHelper = new \OC\Setup(\OC::$server->getConfig());
+ $setupHelper = new \OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults());
if(!$setupHelper->isCurrentHtaccess()) {
throw new \OC\HintException('.htaccess file has the wrong version. Please upload the correct version. Maybe you forgot to replace it after updating?');
}