normalizing tags for status_network
This commit is contained in:
parent
c5e89527d9
commit
7065450f03
@ -27,7 +27,8 @@ class Status_network extends Safe_DataObject
|
|||||||
/* the code below is auto generated do not remove the above tag */
|
/* the code below is auto generated do not remove the above tag */
|
||||||
|
|
||||||
public $__table = 'status_network'; // table name
|
public $__table = 'status_network'; // table name
|
||||||
public $nickname; // varchar(64) primary_key not_null
|
public $site_id; // int(4) primary_key not_null
|
||||||
|
public $nickname; // varchar(64) unique_key not_null
|
||||||
public $hostname; // varchar(255) unique_key
|
public $hostname; // varchar(255) unique_key
|
||||||
public $pathname; // varchar(255) unique_key
|
public $pathname; // varchar(255) unique_key
|
||||||
public $dbhost; // varchar(255)
|
public $dbhost; // varchar(255)
|
||||||
@ -39,7 +40,6 @@ class Status_network extends Safe_DataObject
|
|||||||
public $logo; // varchar(255)
|
public $logo; // varchar(255)
|
||||||
public $created; // datetime() not_null
|
public $created; // datetime() not_null
|
||||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||||
public $tags; // text
|
|
||||||
|
|
||||||
/* Static get */
|
/* Static get */
|
||||||
function staticGet($k,$v=NULL) {
|
function staticGet($k,$v=NULL) {
|
||||||
@ -308,9 +308,55 @@ class Status_network extends Safe_DataObject
|
|||||||
*/
|
*/
|
||||||
function getTags()
|
function getTags()
|
||||||
{
|
{
|
||||||
return array_filter(explode("|", strval($this->tags)));
|
$result = array();
|
||||||
|
|
||||||
|
$tags = new Status_network_tag();
|
||||||
|
$tags->site_id = $this->site_id;
|
||||||
|
if ($tags->find()) {
|
||||||
|
while ($tags->fetch()) {
|
||||||
|
$result[] = $tags->tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save a given set of tags
|
||||||
|
* @param array tags
|
||||||
|
*/
|
||||||
|
function setTags($tags)
|
||||||
|
{
|
||||||
|
$this->clearTags();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$snt = new Status_network_tag();
|
||||||
|
$snt->site_id = $this->site_id;
|
||||||
|
$snt->tag = $tag;
|
||||||
|
$snt->created = common_sql_now();
|
||||||
|
|
||||||
|
$id = $snt->insert();
|
||||||
|
if (!$id) {
|
||||||
|
throw new Exception(_("Unable to save tag."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearTags()
|
||||||
|
{
|
||||||
|
$tag = new Status_network_tag();
|
||||||
|
$tag->site_id = $this->site_id;
|
||||||
|
|
||||||
|
if ($tag->find()) {
|
||||||
|
while($tag->fetch()) {
|
||||||
|
$tag->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag->free();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this site record has a particular meta-info tag attached.
|
* Check if this site record has a particular meta-info tag attached.
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
|
69
classes/Status_network_tag.php
Normal file
69
classes/Status_network_tag.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* StatusNet - the distributed open-source microblogging tool
|
||||||
|
* Copyright (C) 2008, 2009, 2010 StatusNet, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('STATUSNET')) { exit(1); }
|
||||||
|
|
||||||
|
class Status_network_tag extends Safe_DataObject
|
||||||
|
{
|
||||||
|
###START_AUTOCODE
|
||||||
|
/* the code below is auto generated do not remove the above tag */
|
||||||
|
|
||||||
|
public $__table = 'status_network_tag'; // table name
|
||||||
|
public $site_id; // int(4) primary_key not_null
|
||||||
|
public $tag; // varchar(64) primary_key not_null
|
||||||
|
public $created; // datetime() not_null
|
||||||
|
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
global $_DB_DATAOBJECT;
|
||||||
|
|
||||||
|
$sn = new Status_network();
|
||||||
|
$sn->_connect();
|
||||||
|
|
||||||
|
$config['db']['table_'. $this->__table] = $sn->_database;
|
||||||
|
|
||||||
|
$this->_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Static get */
|
||||||
|
function staticGet($k,$v=null)
|
||||||
|
{
|
||||||
|
$i = DB_DataObject::staticGet('Status_network_tag',$k,$v);
|
||||||
|
|
||||||
|
// Don't use local process cache; if we're fetching multiple
|
||||||
|
// times it's because we're reloading it in a long-running
|
||||||
|
// process; we need a fresh copy!
|
||||||
|
global $_DB_DATAOBJECT;
|
||||||
|
unset($_DB_DATAOBJECT['CACHE']['status_network_tag']);
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the code above is auto generated do not remove the tag below */
|
||||||
|
###END_AUTOCODE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function pkeyGet($kv)
|
||||||
|
{
|
||||||
|
return Memcached_DataObject::pkeyGet('Status_network_tag', $kv);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
[status_network]
|
[status_network]
|
||||||
|
side_id = 129
|
||||||
nickname = 130
|
nickname = 130
|
||||||
hostname = 2
|
hostname = 2
|
||||||
pathname = 2
|
pathname = 2
|
||||||
@ -11,9 +12,19 @@ theme = 2
|
|||||||
logo = 2
|
logo = 2
|
||||||
created = 142
|
created = 142
|
||||||
modified = 384
|
modified = 384
|
||||||
tags = 34
|
|
||||||
|
|
||||||
[status_network__keys]
|
[status_network__keys]
|
||||||
nickname = K
|
site_id = K
|
||||||
|
nickname = U
|
||||||
hostname = U
|
hostname = U
|
||||||
pathname = U
|
pathname = U
|
||||||
|
|
||||||
|
[status_network_tag]
|
||||||
|
site_id = 129
|
||||||
|
tag = 130
|
||||||
|
created = 142
|
||||||
|
|
||||||
|
[status_network_tag__keys]
|
||||||
|
site_id = K
|
||||||
|
tag = K
|
||||||
|
|
||||||
|
16
db/site.sql
16
db/site.sql
@ -1,8 +1,9 @@
|
|||||||
/* For managing multiple sites */
|
/* For managing multiple sites */
|
||||||
|
|
||||||
create table status_network (
|
create table status_network (
|
||||||
|
|
||||||
nickname varchar(64) primary key comment 'nickname',
|
site_id integer auto_increment primary key comment 'unique id',
|
||||||
|
nickname varchar(64) unique key comment 'nickname',
|
||||||
hostname varchar(255) unique key comment 'alternate hostname if any',
|
hostname varchar(255) unique key comment 'alternate hostname if any',
|
||||||
pathname varchar(255) unique key comment 'alternate pathname if any',
|
pathname varchar(255) unique key comment 'alternate pathname if any',
|
||||||
|
|
||||||
@ -15,9 +16,16 @@ create table status_network (
|
|||||||
theme varchar(255) comment 'theme name',
|
theme varchar(255) comment 'theme name',
|
||||||
logo varchar(255) comment 'site logo',
|
logo varchar(255) comment 'site logo',
|
||||||
|
|
||||||
tags text comment 'site meta-info tags (pipe-separated)',
|
|
||||||
|
|
||||||
created datetime not null comment 'date this record was created',
|
created datetime not null comment 'date this record was created',
|
||||||
modified timestamp comment 'date this record was modified'
|
modified timestamp comment 'date this record was modified'
|
||||||
|
|
||||||
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
|
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||||
|
|
||||||
|
create table status_network_tag (
|
||||||
|
site_id integer comment 'unique id',
|
||||||
|
tag varchar(64) comment 'tag name',
|
||||||
|
created datetime not null comment 'date the record was created',
|
||||||
|
|
||||||
|
constraint primary key (site_id, tag)
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||||
|
|
||||||
|
@ -39,11 +39,10 @@ if (count($args) < 1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$nickname = $args[0];
|
$nickname = $args[0];
|
||||||
|
|
||||||
$sn = Status_network::memGet('nickname', $nickname);
|
$sn = Status_network::memGet('nickname', $nickname);
|
||||||
|
|
||||||
if (empty($sn)) {
|
if (empty($sn)) {
|
||||||
print "No such site.\n";
|
print "No such site ($nickname).\n";
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,16 +53,13 @@ if (count($args) == 1) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
$tag = $args[1];
|
$tag = $args[1];
|
||||||
|
|
||||||
$i = array_search($tag, $tags);
|
$i = array_search($tag, $tags);
|
||||||
|
|
||||||
if ($i !== false) {
|
if ($i !== false) {
|
||||||
if (have_option('d', 'delete')) { // Delete
|
if (have_option('d', 'delete')) { // Delete
|
||||||
unset($tags[$i]);
|
unset($tags[$i]);
|
||||||
|
|
||||||
$orig = clone($sn);
|
$result = $sn->setTags($tags);
|
||||||
$sn->tags = implode('|', $tags);
|
|
||||||
$result = $sn->update($orig);
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
print "Couldn't update.\n";
|
print "Couldn't update.\n";
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@ -78,9 +74,7 @@ if ($i !== false) {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
} else {
|
} else {
|
||||||
$tags[] = $tag;
|
$tags[] = $tag;
|
||||||
$orig = clone($sn);
|
$result = $sn->setTags($tags);
|
||||||
$sn->tags = implode('|', $tags);
|
|
||||||
$result = $sn->update($orig);
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
print "Couldn't update.\n";
|
print "Couldn't update.\n";
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
@ -44,8 +44,8 @@ mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS
|
|||||||
|
|
||||||
GRANT ALL ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password';
|
GRANT ALL ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password';
|
||||||
GRANT ALL ON $database.* TO '$username'@'%' IDENTIFIED BY '$password';
|
GRANT ALL ON $database.* TO '$username'@'%' IDENTIFIED BY '$password';
|
||||||
INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created, tags)
|
INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created)
|
||||||
VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now(), '$tags');
|
VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now());
|
||||||
|
|
||||||
ENDOFCOMMANDS
|
ENDOFCOMMANDS
|
||||||
|
|
||||||
@ -56,6 +56,8 @@ done
|
|||||||
|
|
||||||
php $PHPBASE/scripts/checkschema.php -s"$server"
|
php $PHPBASE/scripts/checkschema.php -s"$server"
|
||||||
|
|
||||||
|
php $PHPBASE/scripts/settag.php -s"$server" "$nickname" "$tags"
|
||||||
|
|
||||||
php $PHPBASE/scripts/registeruser.php \
|
php $PHPBASE/scripts/registeruser.php \
|
||||||
-s"$server" \
|
-s"$server" \
|
||||||
-n"$nickname" \
|
-n"$nickname" \
|
||||||
|
Loading…
Reference in New Issue
Block a user