X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FStatus_network.php;h=3498b4bd24b4ae18a0a9f5213ff9666beff92977;hb=2f86cd860231f92213950d439e9a109b7a5f11c4;hp=a0f3ba5f785525f7435237f7353898c2b20ed5ff;hpb=189d34173311828ccfe0aec5f381ad26887384ce;p=quix0rs-gnu-social.git diff --git a/classes/Status_network.php b/classes/Status_network.php index a0f3ba5f78..3498b4bd24 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -29,20 +29,21 @@ class Status_network extends Safe_DataObject public $__table = 'status_network'; // table name public $site_id; // int(4) primary_key not_null public $nickname; // varchar(64) unique_key not_null - public $hostname; // varchar(255) unique_key - public $pathname; // varchar(255) unique_key - public $dbhost; // varchar(255) - public $dbuser; // varchar(255) - public $dbpass; // varchar(255) - public $dbname; // varchar(255) - public $sitename; // varchar(255) - public $theme; // varchar(255) - public $logo; // varchar(255) + public $hostname; // varchar(191) unique_key not 255 because utf8mb4 takes more space + public $pathname; // varchar(191) unique_key not 255 because utf8mb4 takes more space + public $dbhost; // varchar(191) not 255 because utf8mb4 takes more space + public $dbuser; // varchar(191) not 255 because utf8mb4 takes more space + public $dbpass; // varchar(191) not 255 because utf8mb4 takes more space + public $dbname; // varchar(191) not 255 because utf8mb4 takes more space + public $sitename; // varchar(191) not 255 because utf8mb4 takes more space + public $theme; // varchar(191) not 255 because utf8mb4 takes more space + public $logo; // varchar(191) not 255 because utf8mb4 takes more space public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { + static function getKV($k,$v=NULL) { + // TODO: This must probably be turned into a non-static call $i = DB_DataObject::staticGet('Status_network',$k,$v); // Don't use local process cache; if we're fetching multiple @@ -56,8 +57,9 @@ class Status_network extends Safe_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - static $cache = null; - static $cacheInitialized = false; + // XXX: made public so Status_network_tag can eff with it + public static $cache = null; + public static $cacheInitialized = false; static $base = null; static $wildcard = null; @@ -68,13 +70,16 @@ class Status_network extends Safe_DataObject * @param string $dbname * @param array $servers memcached servers to use for caching config info */ - static function setupDB($dbhost, $dbuser, $dbpass, $dbname, $servers) + static function setupDB($dbhost, $dbuser, $dbpass, $dbname, array $servers) { global $config; $config['db']['database_'.$dbname] = "mysqli://$dbuser:$dbpass@$dbhost/$dbname"; $config['db']['ini_'.$dbname] = INSTALLDIR.'/classes/status_network.ini'; - $config['db']['table_status_network'] = $dbname; + + foreach (array('status_network', 'status_network_tag', 'unavailable_status_network') as $table) { + $config['db']['table_'.$table] = $dbname; + } if (class_exists('Memcache')) { self::$cache = new Memcache(); @@ -88,12 +93,18 @@ class Status_network extends Safe_DataObject // or a single-process script which is switching // configurations. $persist = php_sapi_name() != 'cli' || self::$cacheInitialized; - if (is_array($servers)) { - foreach($servers as $server) { - self::$cache->addServer($server, 11211, $persist); + if (!is_array($servers)) { + $servers = array($servers); + } + foreach($servers as $server) { + $parts = explode(':', $server); + $server = $parts[0]; + if (count($parts) > 1) { + $port = $parts[1]; + } else { + $port = 11211; } - } else { - self::$cache->addServer($servers, 11211, $persist); + self::$cache->addServer($server, $port, $persist); } self::$cacheInitialized = true; } @@ -102,13 +113,13 @@ class Status_network extends Safe_DataObject } static function cacheKey($k, $v) { - return 'statusnet:' . self::$base . ':status_network:'.$k.':'.$v; + return 'gnusocial:' . self::$base . ':status_network:'.$k.':'.$v; } static function memGet($k, $v) { if (!self::$cache) { - return self::staticGet($k, $v); + return self::getKV($k, $v); } $ck = self::cacheKey($k, $v); @@ -116,7 +127,7 @@ class Status_network extends Safe_DataObject $sn = self::$cache->get($ck); if (empty($sn)) { - $sn = self::staticGet($k, $v); + $sn = self::getKV($k, $v); if (!empty($sn)) { self::$cache->set($ck, clone($sn)); } @@ -136,12 +147,12 @@ class Status_network extends Safe_DataObject } } - function update($orig=null) + function update($dataObject=false) { - if (is_object($orig)) { - $orig->decache(); # might be different keys + if (is_object($dataObject)) { + $dataObject->decache(); # might be different keys } - return parent::update($orig); + return parent::update($dataObject); } /** @@ -167,18 +178,17 @@ class Status_network extends Safe_DataObject ' WHERE nickname = ' . $this->_quote($this->nickname); $orig->decache(); $result = $this->query($qry); - if ($result) { - $this->encache(); - } + $this->decache(); + return $result; } - - function delete() + + function delete($useWhere=false) { $this->decache(); # while we still have the values! - return parent::delete(); + return parent::delete($useWhere); } - + /** * @param string $servername hostname * @param string $wildcard hostname suffix to match wildcard config @@ -308,29 +318,15 @@ class Status_network extends Safe_DataObject */ function getTags() { - $result = array(); - - $tags = new Status_network_tag(); - $tags->site_id = $this->site_id; - if ($tags->find()) { - while ($tags->fetch()) { - $result[] = $tags->tag; - } - } - - // XXX : for backwards compatibility - if (empty($result)) { - return explode('|', $this->tags); - } - - return $result; + return Status_network_tag::getTags($this->site_id); } /** * Save a given set of tags * @param array tags + * @fixme only add/remove differentials */ - function setTags($tags) + function setTags(array $tags) { $this->clearTags(); foreach ($tags as $tag) { @@ -339,9 +335,10 @@ class Status_network extends Safe_DataObject $snt->site_id = $this->site_id; $snt->tag = $tag; $snt->created = common_sql_now(); - + $id = $snt->insert(); if (!$id) { + // TRANS: Exception thrown when a tag cannot be saved. throw new Exception(_("Unable to save tag.")); } } @@ -363,7 +360,7 @@ class Status_network extends Safe_DataObject $tag->free(); } - + /** * Check if this site record has a particular meta-info tag attached. * @param string $tag