/** * Change site configuration to site specified by nickname, * if set up via Status_network. If not, sites other than * the current will fail horribly. * * May throw exception or trigger a fatal error if the given * site is missing or configured incorrectly. * * @param string $nickname */ public static function switchSite($nickname) { if ($nickname == self::currentSite()) { return true; } $sn = Status_network::getKV('nickname', $nickname); if (empty($sn)) { return false; throw new Exception("No such site nickname '{$nickname}'"); } $server = $sn->getServerName(); self::init($server); }
function saveStatusNetwork() { Status_network::setupDB($this->sitehost, $this->rootname, $this->rootpass, $this->sitedb, array()); $sn = new Status_network(); $sn->nickname = $this->nickname; $sn->dbhost = $this->host; $sn->dbuser = $this->username; $sn->dbpass = $this->password; $sn->dbname = $this->database; $sn->sitename = $this->sitename; $sn->created = common_sql_now(); $result = $sn->insert(); if (!$result) { throw new ServerException("Could not create status_network: " . print_r($sn, true)); } // Re-fetch; stupid auto-increment integer isn't working $sn = Status_network::getKV('nickname', $sn->nickname); if (empty($sn)) { throw new ServerException("Created {$this->nickname} status_network and could not find it again."); } // Set default tags $tags = $this->tags; // Add domain tag $tags[] = 'domain=' . $this->domain; $sn->setTags($tags); $this->sn = $sn; }
/** * (Re)load runtime configuration for a given site by nickname, * triggered by a broadcast to the 'statusnet-control' topic. * * Configuration changes in database should update, but config * files might not. * * @param array $frame Stomp frame * @return bool true to continue; false to stop further processing. */ protected function updateSiteConfig($nickname) { $sn = Status_network::getKV('nickname', $nickname); if ($sn) { $this->switchSite($nickname); if (!in_array($nickname, $this->sites)) { $this->addSite(); } $this->stats('siteupdate'); } else { $this->_log(LOG_ERR, "Ignoring ping for unrecognized new site {$nickname}"); } }
static function siteForDomain($domain) { $snt = Status_network_tag::withTag('domain=' . $domain); while ($snt->fetch()) { $sn = Status_network::getKV('site_id', $snt->site_id); if (!empty($sn)) { return $sn; } } return null; }