Skip to content
Snippets Groups Projects
Select Git revision
  • 84a8aea410053686678f8efa6ba00ac63d31133e
  • master default protected
2 results

setup.php

Blame
  • setup.php 31.54 KiB
    <?php
    
    class DatabaseSetupException extends Exception
    {
    	private $hint;
    
    	public function __construct($message, $hint, $code = 0, Exception $previous = null) {
    		$this->hint = $hint;
    		parent::__construct($message, $code, $previous);
    	}
    
    	public function __toString() {
    		return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n";
    	}
    
    	public function getHint() {
    		return $this->hint;
    	}
    }
    
    class OC_Setup {
    
    	public static function getTrans(){
    		return OC_L10N::get('lib');
    	}
    
    	public static function install($options) {
    		$l = self::getTrans();
    
    		$error = array();
    		$dbtype = $options['dbtype'];
    
    		if(empty($options['adminlogin'])) {
    			$error[] = $l->t('Set an admin username.');
    		}
    		if(empty($options['adminpass'])) {
    			$error[] = $l->t('Set an admin password.');
    		}
    		if(empty($options['directory'])) {
    			$options['directory'] = OC::$SERVERROOT."/data";
    		}
    
    		if($dbtype == 'mysql' or $dbtype == 'pgsql' or $dbtype == 'oci' or $dbtype == 'mssql') { //mysql and postgresql needs more config options
    			if($dbtype == 'mysql')
    				$dbprettyname = 'MySQL';
    			else if($dbtype == 'pgsql')
    				$dbprettyname = 'PostgreSQL';
    			else if ($dbtype == 'mssql')
    				$dbprettyname = 'MS SQL Server';
    			else
    				$dbprettyname = 'Oracle';
    
    
    			if(empty($options['dbuser'])) {
    				$error[] = $l->t("%s enter the database username.", array($dbprettyname));
    			}
    			if(empty($options['dbname'])) {
    				$error[] = $l->t("%s enter the database name.", array($dbprettyname));
    			}
    			if(substr_count($options['dbname'], '.') >= 1) {
    				$error[] = $l->t("%s you may not use dots in the database name", array($dbprettyname));
    			}
    			if($dbtype != 'oci' && empty($options['dbhost'])) {
    				$error[] = $l->t("%s set the database host.", array($dbprettyname));
    			}
    		}
    
    		if(count($error) == 0) { //no errors, good
    			$username = htmlspecialchars_decode($options['adminlogin']);
    			$password = htmlspecialchars_decode($options['adminpass']);