* @author Craig Andrews <candrews@integralblue.com>
* @author Eric Helgeson <helfire@Erics-MBP.local>
* @author Evan Prodromou <evan@status.net>
+ * @author Mikael Nordfeldth <mmn@hethane.se>
* @author Robin Millette <millette@controlyourself.ca>
* @author Sarven Capadisli <csarven@status.net>
* @author Tom Adams <tom@holizz.com>
abstract class Installer
{
/** Web site info */
- public $sitename, $server, $path, $fancy, $siteProfile;
+ public $sitename, $server, $path, $fancy, $siteProfile, $ssl;
/** DB info */
public $host, $database, $dbtype, $username, $password, $db;
/** Administrator info */
'" is invalid; should be plain letters and numbers no longer than 64 characters.', true);
$fail = true;
}
- // @fixme hardcoded list; should use User::allowed_nickname()
+ // @fixme hardcoded list; should use Nickname::isValid()
// if/when it's safe to have loaded the infrastructure here
$blacklist = array('main', 'panel', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'bookmarklet', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook');
if (in_array($this->adminNick, $blacklist)) {
$this->updateStatus(sprintf("Adding %s data to database...", $name));
$res = $this->runDbScript($scr.'.sql', $conn);
if ($res === false) {
- $this->updateStatus(sprintf("Can't run %d script.", $name), true);
+ $this->updateStatus(sprintf("Can't run %s script.", $name), true);
return false;
}
}
*/
function connectDatabase($dsn)
{
- // @fixme move this someplace more sensible
- //set_include_path(INSTALLDIR . '/extlib' . PATH_SEPARATOR . get_include_path());
- require_once 'DB.php';
- return DB::connect($dsn);
+ global $_DB;
+ return $_DB->connect($dsn);
}
/**
'sitename' => $this->sitename,
'server' => $this->server,
'path' => $this->path,
+ 'ssl' => in_array($this->ssl, array('never', 'sometimes', 'always'))
+ ? $this->ssl
+ : 'never',
'db_database' => $this->db['database'],
- 'db_type' => $this->db['type'],
- 'site_profile' => $this->siteProfile,
- 'nickname' => $this->adminNick
+ 'db_type' => $this->db['type']
));
// assemble configuration file in a string
$cfg = "<?php\n".
- "if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }\n\n".
+ "if (!defined('GNUSOCIAL')) { exit(1); }\n\n".
// site name
"\$config['site']['name'] = {$vals['sitename']};\n\n".
// site location
"\$config['site']['server'] = {$vals['server']};\n".
"\$config['site']['path'] = {$vals['path']}; \n\n".
+ "\$config['site']['ssl'] = {$vals['ssl']}; \n\n".
// checks if fancy URLs are enabled
($this->fancy ? "\$config['site']['fancy'] = true;\n\n":'').
// database
"\$config['db']['database'] = {$vals['db_database']};\n\n".
($this->db['type'] == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n":'').
- "\$config['db']['type'] = {$vals['db_type']};\n\n".
+ "\$config['db']['type'] = {$vals['db_type']};\n\n";
+
+ // Auto memcache support detection
+ $cfg .= '
+foreach(array("Memcache", "Memcached") as $plugin) :
+ if (class_exists($plugin)) {
+ addPlugin($plugin);
+ break;
+ }
+endforeach;
+';
+
+ // Normalize line endings for Windows servers
+ $cfg = str_replace("\n", PHP_EOL, $cfg);
+
+ // write configuration file out to install directory
+ $res = file_put_contents(INSTALLDIR.'/config.php', $cfg);
- // site profile
- "\$config['site']['profile'] = {$vals['site_profile']};\n";
+ return $res;
+ }
+
+ /**
+ * Write the site profile. We do this after creating the initial user
+ * in case the site profile is set to single user. This gets around the
+ * 'chicken-and-egg' problem of the system requiring a valid user for
+ * single user mode, before the intial user is actually created. Yeah,
+ * we should probably do this in smarter way.
+ *
+ * @return int res number of bytes written
+ */
+ function writeSiteProfile()
+ {
+ $vals = $this->phpVals(array(
+ 'site_profile' => $this->siteProfile,
+ 'nickname' => $this->adminNick
+ ));
+
+ $cfg =
+ // site profile
+ "\$config['site']['profile'] = {$vals['site_profile']};\n";
if ($this->siteProfile == "singleuser") {
$cfg .= "\$config['singleuser']['nickname'] = {$vals['nickname']};\n\n";
$cfg = str_replace("\n", PHP_EOL, $cfg);
// write configuration file out to install directory
- $res = file_put_contents(INSTALLDIR.'/config.php', $cfg);
+ $res = file_put_contents(INSTALLDIR.'/config.php', $cfg, FILE_APPEND);
return $res;
}
$this->updateStatus("Initializing...");
ini_set('display_errors', 1);
error_reporting(E_ALL);
+ if (!defined('GNUSOCIAL')) {
+ define('GNUSOCIAL', true);
+ }
if (!defined('STATUSNET')) {
- define('STATUSNET', 1);
+ define('STATUSNET', true);
}
require_once INSTALLDIR . '/lib/framework.php';
StatusNet::initDefaults($this->server, $this->path);
return false;
}
+ // Make sure we can write to the file twice
+ $oldUmask = umask(000);
+
if (!$this->skipConfig) {
$this->updateStatus("Writing config file...");
$res = $this->writeConf();
}
}
+ if (!$this->skipConfig) {
+ $this->updateStatus("Setting site profile...");
+ $res = $this->writeSiteProfile();
+
+ if (!$res) {
+ $this->updateStatus("Can't write to config file.", true);
+ return false;
+ }
+ }
+
+ // Restore original umask
+ umask($oldUmask);
+ // Set permissions back to something decent
+ chmod(INSTALLDIR.'/config.php', 0644);
+
/*
TODO https needs to be considered
*/