forked from GNUsocial/gnu-social
		
	actions
avatar
background
classes
db
doc-src
extlib
file
js
lib
accountsettingsaction.php
action.php
adminform.php
adminpanelaction.php
api.php
apiauth.php
apibareauth.php
apioauth.php
apioauthstore.php
apiprivateauth.php
applicationeditform.php
applicationlist.php
arraywrapper.php
atom10entry.php
atom10feed.php
atomnoticefeed.php
attachmentlist.php
attachmentnoticesection.php
attachmenttagcloudsection.php
authenticationplugin.php
authorizationplugin.php
blockform.php
cache.php
channel.php
clienterroraction.php
clientexception.php
columndef.php
command.php
commandinterpreter.php
common.php
connectsettingsaction.php
currentuserdesignaction.php
curry.php
daemon.php
dberroraction.php
dbqueuemanager.php
default.php
deleteuserform.php
designsettings.php
disfavorform.php
distribqueuehandler.php
error.php
event.php
favorform.php
featureduserssection.php
feed.php
feedlist.php
form.php
galleryaction.php
groupdesignaction.php
groupeditform.php
grouplist.php
groupminilist.php
groupnav.php
groupsbymemberssection.php
groupsbypostssection.php
groupsection.php
grouptagcloudsection.php
htmloutputter.php
httpclient.php
imagefile.php
iomanager.php
iomaster.php
jabber.php
jabberqueuehandler.php
joinform.php
jsonsearchresultslist.php
language.php
leaveform.php
liberalstomp.php
location.php
logingroupnav.php
mail.php
mailbox.php
mailhandler.php
mediafile.php
messageform.php
microid.php
mysqlschema.php
noticeform.php
noticelist.php
noticesection.php
nudgeform.php
oauthclient.php
oauthstore.php
omb.php
ombqueuehandler.php
ownerdesignaction.php
parallelizingdaemon.php
personalgroupnav.php
personaltagcloudsection.php
pgsqlschema.php
ping.php
pingqueuehandler.php
plugin.php
pluginqueuehandler.php
popularnoticesection.php
profileaction.php
profileactionform.php
profileformaction.php
profilelist.php
profileminilist.php
profilesection.php
publicgroupnav.php
publicqueuehandler.php
queued_xmpp.php
queuehandler.php
queuemanager.php
queuemonitor.php
repeatform.php
right.php
router.php
rssaction.php
sandboxform.php
schema.php
search_engines.php
searchaction.php
searchgroupnav.php
section.php
servererroraction.php
serverexception.php
settingsaction.php
silenceform.php
smsqueuehandler.php
snapshot.php
spawningdaemon.php
statusnet.php
stompqueuemanager.php
subgroupnav.php
subpeopletagcloudsection.php
subs.php
subscribeform.php
subscriberspeopleselftagcloudsection.php
subscriberspeopletagcloudsection.php
subscriptionlist.php
subscriptionspeopleselftagcloudsection.php
subscriptionspeopletagcloudsection.php
tabledef.php
tagcloudsection.php
theme.php
topposterssection.php
uapplugin.php
unblockform.php
unqueuemanager.php
unsandboxform.php
unsilenceform.php
unsubscribeform.php
userprofile.php
util.php
webcolor.php
widget.php
xmloutputter.php
xmlstringer.php
xmppmanager.php
xmppoutqueuehandler.php
xrdsoutputter.php
local
locale
plugins
scripts
tests
theme
tpl
.gitignore
COPYING
EVENTS.txt
Makefile
README
apple-touch-icon.png
config.php.sample
favicon.ico
htaccess.sample
index.php
install.php
lighttpd.conf.example
		
			
				
	
	
		
			171 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			171 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/**
 | 
						|
 * StatusNet, the distributed open-source microblogging tool
 | 
						|
 *
 | 
						|
 * Database schema utilities
 | 
						|
 *
 | 
						|
 * PHP version 5
 | 
						|
 *
 | 
						|
 * LICENCE: 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/>.
 | 
						|
 *
 | 
						|
 * @category  Database
 | 
						|
 * @package   StatusNet
 | 
						|
 * @author    Evan Prodromou <evan@status.net>
 | 
						|
 * @copyright 2009 StatusNet, Inc.
 | 
						|
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 | 
						|
 * @link      http://status.net/
 | 
						|
 */
 | 
						|
 | 
						|
if (!defined('STATUSNET')) {
 | 
						|
    exit(1);
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * A class encapsulating the structure of a column in a table.
 | 
						|
 *
 | 
						|
 * @category Database
 | 
						|
 * @package  StatusNet
 | 
						|
 * @author   Evan Prodromou <evan@status.net>
 | 
						|
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 | 
						|
 * @link     http://status.net/
 | 
						|
 */
 | 
						|
 | 
						|
class ColumnDef
 | 
						|
{
 | 
						|
    /** name of the column. */
 | 
						|
    public $name;
 | 
						|
    /** type of column, e.g. 'int', 'varchar' */
 | 
						|
    public $type;
 | 
						|
    /** size of the column. */
 | 
						|
    public $size;
 | 
						|
    /** boolean flag; can it be null? */
 | 
						|
    public $nullable;
 | 
						|
    /**
 | 
						|
     * type of key: null = no key; 'PRI' => primary;
 | 
						|
     * 'UNI' => unique key; 'MUL' => multiple values.
 | 
						|
     */
 | 
						|
    public $key;
 | 
						|
    /** default value if any. */
 | 
						|
    public $default;
 | 
						|
    /** 'extra' stuff. Returned by MySQL, largely
 | 
						|
     * unused. */
 | 
						|
    public $extra;
 | 
						|
    /** auto increment this field if no value is specific for it during an insert **/
 | 
						|
    public $auto_increment;
 | 
						|
 | 
						|
    /**
 | 
						|
     * Constructor.
 | 
						|
     *
 | 
						|
     * @param string  $name     name of the column
 | 
						|
     * @param string  $type     type of the column
 | 
						|
     * @param int     $size     size of the column
 | 
						|
     * @param boolean $nullable can this be null?
 | 
						|
     * @param string  $key      type of key
 | 
						|
     * @param value   $default  default value
 | 
						|
     * @param value   $extra    unused
 | 
						|
     * @param boolean $auto_increment
 | 
						|
     */
 | 
						|
 | 
						|
    function __construct($name=null, $type=null, $size=null,
 | 
						|
                         $nullable=true, $key=null, $default=null,
 | 
						|
                         $extra=null, $auto_increment=false)
 | 
						|
    {
 | 
						|
        $this->name     = strtolower($name);
 | 
						|
        $this->type     = strtolower($type);
 | 
						|
        $this->size     = $size+0;
 | 
						|
        $this->nullable = $nullable;
 | 
						|
        $this->key      = $key;
 | 
						|
        $this->default  = $default;
 | 
						|
        $this->extra    = $extra;
 | 
						|
        $this->auto_increment = $auto_increment;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Compares this columndef with another to see
 | 
						|
     * if they're functionally equivalent.
 | 
						|
     *
 | 
						|
     * @param ColumnDef $other column to compare
 | 
						|
     *
 | 
						|
     * @return boolean true if equivalent, otherwise false.
 | 
						|
     */
 | 
						|
 | 
						|
    function equals($other)
 | 
						|
    {
 | 
						|
        return ($this->name == $other->name &&
 | 
						|
                $this->_typeMatch($other) &&
 | 
						|
                $this->_defaultMatch($other) &&
 | 
						|
                $this->_nullMatch($other) &&
 | 
						|
                $this->key == $other->key &&
 | 
						|
                $this->auto_increment == $other->auto_increment);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Does the type of this column match the
 | 
						|
     * type of the other column?
 | 
						|
     *
 | 
						|
     * Checks the type and size of a column. Tries
 | 
						|
     * to ignore differences between synonymous
 | 
						|
     * data types, like 'integer' and 'int'.
 | 
						|
     *
 | 
						|
     * @param ColumnDef $other other column to check
 | 
						|
     *
 | 
						|
     * @return boolean true if they're about equivalent
 | 
						|
     */
 | 
						|
 | 
						|
    private function _typeMatch($other)
 | 
						|
    {
 | 
						|
        switch ($this->type) {
 | 
						|
        case 'integer':
 | 
						|
        case 'int':
 | 
						|
            return ($other->type == 'integer' ||
 | 
						|
                    $other->type == 'int');
 | 
						|
            break;
 | 
						|
        default:
 | 
						|
            return ($this->type == $other->type &&
 | 
						|
                    $this->size == $other->size);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Does the default behaviour of this column match
 | 
						|
     * the other?
 | 
						|
     *
 | 
						|
     * @param ColumnDef $other other column to check
 | 
						|
     *
 | 
						|
     * @return boolean true if defaults are effectively the same.
 | 
						|
     */
 | 
						|
 | 
						|
    private function _defaultMatch($other)
 | 
						|
    {
 | 
						|
        return ((is_null($this->default) && is_null($other->default)) ||
 | 
						|
                ($this->default == $other->default));
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Does the null behaviour of this column match
 | 
						|
     * the other?
 | 
						|
     *
 | 
						|
     * @param ColumnDef $other other column to check
 | 
						|
     *
 | 
						|
     * @return boolean true if these columns 'null' the same.
 | 
						|
     */
 | 
						|
 | 
						|
    private function _nullMatch($other)
 | 
						|
    {
 | 
						|
        return ((!is_null($this->default) && !is_null($other->default) &&
 | 
						|
                 $this->default == $other->default) ||
 | 
						|
                ($this->nullable == $other->nullable));
 | 
						|
    }
 | 
						|
}
 |