@ -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(
@ -32,13 +47,6 @@ class Setup {
'sqlite3' => '\OC\Setup\Sqlite',
);
/**
* @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
@ -116,12 +124,91 @@ class Setup {
return $supportedDatabases;
}
/**
* 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?');
}