/**
  * @see IWebApplicationInstaller_Script::run()
  */
 public function run()
 {
     $wai = WAI::getInstance();
     if (!function_exists('mysql_connect')) {
         $this->error_msg = 'MySQL support not included in PHP.';
         return false;
     }
     $conn = @mysql_connect($wai->getRequest('database_server'), null, null);
     if (!$conn || mysql_errno() >= 2000) {
         $this->error_msg = array('can\'t find the a MySQL server on {p1}: {p2}', array($wai->getRequest('database_server'), mysql_error()));
         return false;
     }
     $conn = @mysql_connect($wai->getRequest('database_server'), $wai->getRequest('database_username'), $wai->getRequest('database_password'));
     if (!$conn) {
         $this->error_msg = 'That username/password doesn\'t work';
         return false;
     }
     if (!mysql_get_server_info()) {
         WAI::warningMsg('Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.');
     } else {
         list($majorRequested, $minorRequested) = explode('.', '4.1');
         $result = mysql_query('SELECT VERSION()');
         $row = mysql_fetch_row($result);
         $version = ereg_replace('([A-Za-z-])', '', $row[0]);
         list($majorHas, $minorHas) = explode('.', substr(trim($version), 0, 3));
         if ($majorHas < $majorRequested || $majorHas == $majorRequested && $minorHas < $minorRequested) {
             $this->error_msg = array('MySQL version 4.1 is required, you only have {p1}.{p2}', array($majorHas, $minorHas));
             return false;
         }
     }
     if (@mysql_select_db($wai->getRequest('database_database'))) {
         return true;
     }
     if (@mysql_query('CREATE DATABASE testing123')) {
         mysql_query('DROP DATABASE testing123');
         return true;
     } else {
         $this->error_msg = array('User \'{p1}\' doesn\'t have CREATE DATABASE permissions.', array($wai->getRequest('database_username')));
         return false;
     }
     return true;
     // no error
 }
 /**
  * @see IWebApplicationInstaller_Script::run()
  */
 public function run()
 {
     $alreadyInstalled = false;
     if (file_exists('mysite/_config.php')) {
         // Find the $database variable in the relevant config file without having to execute the config file
         if (preg_match('/\\\\$database\\s*=\\s*[^\\n\\r]+[\\n\\r]/', file_get_contents('mysite/_config.php'), $parts)) {
             eval($parts[0]);
             if ($database) {
                 $alreadyInstalled = true;
                 // Assume that if $databaseConfig is defined in mysite/_config.php, then a non-environment-based installation has
                 // already gone ahead
             } else {
                 if (preg_match('/\\\\$databaseConfig\\s*=\\s*[^\\n\\r]+[\\n\\r]/', file_get_contents('mysite/_config.php'), $parts)) {
                     $alreadyInstalled = true;
                 }
             }
         }
     }
     if ($alreadyInstalled) {
         WAI::warningMsg("'''Note:''' It seems as though SilverStripe is already installed here. If you ask me to install, I will overwrite the '''.htaccess''' and '''mysite/_config.php''' files.");
     }
     return true;
 }
WAI::dropdownField('template', 'Template to install:', array('mysite'), 'mysite', 'You can change the template or download another from the SilverStripe website after installation.');
WAI::checkboxField('send_information', 'Send information on my webserver to SilverStripe (this is only version information, used for statistical purposes)', true, true);
WAI::validateCustom('CheckPreviousInstallstion');
WAI::requestDatabaseSettings(WAI::DB_MySQL, array('min_version' => 4));
WAI::text('=== SilverStripe Administration Account ===');
WAI::textField('admin_email', 'Administrator email:', '', 'We will set up 1 administrator account for you automatically. Enter the email address and password. If you\'d rather log-in with a username instead of an email address, enter that instead.');
WAI::textField('admin_password', 'Administrator password:'******'admin_first_name', 'Administrator first name:');
WAI::textField('admin_surname', 'Administrator surname:');
WAI::validateCustom('CreateAdminAccount');
WAI::text('=== Development Servers ===');
WAI::textareaField('development_servers', 'Development servers:', "localhost\n127.0.0.1", 'SilverStripe allows you to run a site in [http://doc.silverstripe.com/doku.php?id=devmode development mode]. This shows all error messages in the web browser instead of emailing them to the administrator, and allows the database to be built without logging in as administrator. Please enter the host/domain names for servers you will be using for development.');
WAI::requirePhpConfiguration(WAI::PHP5);
WAI::requirePhpConfiguration(WAI::GD2);
WAI::requirePhpConfiguration(WAI::XML);
WAI::requirePhpConfiguration(WAI::DB_MySQL);
WAI::requirePhpConfiguration(WAI::MEMORY_ALLOCATED, array('min' => '32MB'));
WAI::requirePhpConfiguration(WAI::NOT_DEFINED_CLASSES, array('Query', 'HTTPResponse'));
WAI::requirePermission(WAI::FOLDER_EXISTS, WAI::SERVER_ROOT);
WAI::requirePermission(WAI::FOLDER_EXISTS, 'mysite/');
WAI::requirePermission(WAI::FOLDER_EXISTS, 'sapphire/');
WAI::requirePermission(WAI::FOLDER_EXISTS, 'cms/');
WAI::requirePermission(WAI::FOLDER_EXISTS, 'jsparty/');
WAI::requirePermission(WAI::FILE_WRITE, '.htaccess');
WAI::requirePermission(WAI::FILE_WRITE, 'mysite/_config.php');
WAI::requirePermission(WAI::FOLDER_WRITE, 'assets/');
WAI::requirePermission(WAI::FOLDER_WRITE, WAI::TEMPORARY_FOLDER);
WAI::requireWebserverConfiguration(WAI::SERVER_SOFTWARE, array('min_version' => 'Apache/2'));
WAI::requireWebserverConfiguration(WAI::MOD_REWRITE);
WAI::dispatch();
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }