]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/DomainStatusNetwork/domainstatusnetworkinstaller.php
merge 0.9.x into 1.0.x
[quix0rs-gnu-social.git] / plugins / DomainStatusNetwork / domainstatusnetworkinstaller.php
index 891fdd9817b97bc5cd0453f04be3dd076db710c2..ea8220056cf0b2eb4f7e0b5ef2aa644cf30b0d8b 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2011, StatusNet, Inc.
  *
  * Installer class for domain-based multi-homing systems
- * 
+ *
  * PHP version 5
  *
  * This program is free software: you can redistribute it and/or modify
@@ -44,7 +44,6 @@ if (!defined('STATUSNET')) {
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  * @link      http://status.net/
  */
-
 class DomainStatusNetworkInstaller extends Installer
 {
     protected $domain   = null;
@@ -53,7 +52,8 @@ class DomainStatusNetworkInstaller extends Installer
     protected $rootpass = null;
     protected $nickname = null;
     protected $sn       = null;
-    protected $verbose  = false;
+
+    public $verbose     = false;
 
     function __construct($domain)
     {
@@ -94,10 +94,18 @@ class DomainStatusNetworkInstaller extends Installer
         $this->path     = null;
         $this->fancy    = true;
 
+        $datanick = $this->databaseize($this->nickname);
+
         $this->host     = $config['DBHOSTNAME'];
-        $this->database = $this->nickname.$config['DBBASE'];
+        $this->database = $datanick.$config['DBBASE'];
         $this->dbtype   = 'mysql'; // XXX: support others... someday
-        $this->username = $this->nickname.$config['USERBASE'];
+        $this->username = $datanick.$config['USERBASE'];
+
+        // Max size for MySQL
+
+        if (strlen($this->username) > 16) {
+            $this->username = sprintf('%s%08x', substr($this->username, 0, 8), crc32($this->username));
+        }
 
         $pwgen = $config['PWDGEN'];
 
@@ -136,10 +144,14 @@ class DomainStatusNetworkInstaller extends Installer
 
     function setupDatabase()
     {
+        $this->updateStatus('Creating database...');
         $this->createDatabase();
         parent::setupDatabase();
+        $this->updateStatus('Creating file directories...');
         $this->createDirectories();
+        $this->updateStatus('Saving status network...');
         $this->saveStatusNetwork();
+        $this->updateStatus('Checking schema for plugins...');
         $this->checkSchema();
     }
 
@@ -157,11 +169,12 @@ class DomainStatusNetworkInstaller extends Installer
         $sn->dbuser   = $this->username;
         $sn->dbpass   = $this->password;
         $sn->dbname   = $this->database;
+        $sn->sitename = $this->sitename;
 
         $result = $sn->insert();
 
         if (!$result) {
-            throw new ServerException("Couldn't create status_network: " . print_r($sn, true));
+            throw new ServerException("Could not create status_network: " . print_r($sn, true));
         }
 
         $sn->setTags(array('domain='.$this->domain));
@@ -169,7 +182,7 @@ class DomainStatusNetworkInstaller extends Installer
         $this->sn = $sn;
 
     }
-    
+
     function checkSchema()
     {
         $config = $this->getConfig();
@@ -201,7 +214,7 @@ class DomainStatusNetworkInstaller extends Installer
         // Create the New DB
         $res = mysql_connect($this->host, $this->rootname, $this->rootpass);
         if (!$res) {
-            throw new ServerException("Can't connect to {$this->host} as {$this->rootname}");
+            throw new ServerException("Cannot connect to {$this->host} as {$this->rootname}.");
         }
 
         mysql_query("CREATE DATABASE ". mysql_real_escape_string($this->database), $res);
@@ -209,11 +222,11 @@ class DomainStatusNetworkInstaller extends Installer
         $return = mysql_select_db($this->database, $res);
 
         if (!$return) {
-            throw new ServerException("Unable to connect to {$this->database} on {$this->host}");
+            throw new ServerException("Unable to connect to {$this->database} on {$this->host}.");
         }
 
         foreach (array('localhost', '%') as $src) {
-            mysql_query("GRANT ALL ON " . 
+            mysql_query("GRANT ALL ON " .
                         mysql_real_escape_string($this->database).".* TO '" .
                         $this->username . "'@'".$src."' ".
                         "IDENTIFIED BY '".$this->password."'", $res);
@@ -225,7 +238,7 @@ class DomainStatusNetworkInstaller extends Installer
     function getConfig()
     {
         static $config;
-        
+
         $cfg_file = "/etc/statusnet/setup.cfg";
 
         if (empty($config)) {
@@ -273,4 +286,10 @@ class DomainStatusNetworkInstaller extends Installer
                                  $html);
         return html_entity_decode(strip_tags($breakout), ENT_QUOTES, 'UTF-8');
     }
+
+    function databaseize($nickname)
+    {
+        $nickname = str_replace('-', '_', $nickname);
+        return $nickname;
+    }
 }