⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb.sql.upgrader.php

📁 最受欢迎的Joomla社区用户管理收费插件 - Commnity Builder 1.2 RC2。 Community Builder suite (CB) extends the Joomla!
💻 PHP
📖 第 1 页 / 共 5 页
字号:
			case 'null':				if ( $fieldValue != 'NULL' ) {					trigger_error( sprintf( 'CBSQLUpgrader::_phpCleanQuote: ERROR: field type sql:null has not NULL value' ) );				}				$value		=	null;				break;			default:				trigger_error( 'CBSQLUpgrader::_sqlQuoteValueType: ERROR_UNKNOWN_TYPE: ' . htmlspecialchars( $type ), E_USER_NOTICE );				$value		=	(string) $fieldValue;	// false;				break;		}		return $value;	}	/**	 * Cleans and makes a value comparable to the SQL stored value in a comprofilerDBTable object, depending on the type that is enforced.	 * @access private	 *	 * @param  string|null  $fieldValue	 * @param  string  $type	 * @return mixed	 */	function _adjustToStrictType( $fieldValue, $type ) {		$typeArray		=	explode( ':', $type, 3 );		if ( count( $typeArray ) < 2 ) {			$typeArray	=	array( 'const' , $type );		}		$value				=	$fieldValue;		if ( $fieldValue !== null ) {			switch ( $typeArray[1] ) {				case 'int':					if ( is_int( $fieldValue ) || preg_match( '/^\d++$/', $fieldValue ) ) {						$value	=	(int) $fieldValue;					}					break;				case 'float':					if ( is_float( $fieldValue ) || ( preg_match( '/^(((+|-)?\d+(\.\d*)?([Ee](+|-)?\d+)?)|((+|-)?(\d*\.)?\d+([Ee](+|-)?\d+)?))$/', $fieldValue ) ) ) {						$value	=	(float) $fieldValue;					}					break;				case 'formula':					$value		=	$fieldValue;	// this is temporarly done so					break;				case 'field':						// this is temporarly handled here					$value		=	$fieldValue;					break;				case 'datetime':					if ( preg_match( '/^[0-9]{4}-[01][0-9]-[0-3][0-9] [0-2][0-9](:[0-5][0-9]){2}$/', $fieldValue ) ) {						$value	=	(string) $fieldValue;					} else {						$value	=	'';					}					break;				case 'date':					if ( preg_match( '/^[0-9]{4}-[01][0-9]-[0-3][0-9]$/', $fieldValue ) ) {						$value	=	(string) $fieldValue;					} else {						$value	=	'';					}					break;				case 'string':					if ( is_string( $fieldValue ) ) {						$value	=	(string) $fieldValue;					}					break;				case 'null':					if ( $fieldValue === null ) {						$value	=	null;					}					break;				default:					trigger_error( 'CBSQLUpgrader::_sqlQuoteValueType: ERROR_UNKNOWN_TYPE: ' . htmlspecialchars( $type ), E_USER_NOTICE );					$value		=	(string) $fieldValue;	// false;					break;			}		}		return $value;	}	/**	 * Converts a XML description of a SQL index into a full SQL type	 *	 *	<index name="PRIMARY" type="primary">	 *		<column name="id"	/>	 *	</index>	 *	<index name="rate_chars">	 *		<column name="rate" />	 *		<column name="_mychars" nametype="namesuffix" size="8" ordering="DESC" />	 *	</index>	 *	<index name="myrate" type="unique" using="btree">	 *		<column name="rate" />	 *	</index>	 *	 * Returns: $fulltype: 'decimal(16,8) unsigned NULL DEFAULT NULL'	 * @access private	 *	 * @param  CBSimpleXMLElement  $index	 * @param  string              $colNamePrefix    Prefix to add to all column names	 * @return string|boolean                        Full SQL creation type or NULL in case of no index/error	 */	function _fullIndexType( &$index, $colNamePrefix ) {		$sqlIndexText							=	null;		if ( $index->name() == 'index' ) {			// first collect all columns of this index:			$indexColumns						=	array();			foreach ( $index->children() as $column ) {				if ( $column->name() == 'column' ) {					$colNamePrefixed			=	$this->_prefixedName( $column, $colNamePrefix );					$indexColText				=	$this->_db->NameQuote( $colNamePrefixed );					if ( $column->attributes( 'size' ) ) {						$indexColText			.=	' (' . (int) $column->attributes( 'size' ) . ')';					}					if ( $column->attributes( 'ordering' ) ) {						$indexColText			.=	' ' . $this->_db->getEscaped( $column->attributes( 'ordering' ) );					}					$indexColumns[]				=	$indexColText;				}			}			if ( count( $indexColumns ) > 0 ) {				// then build the index creation SQL:				if ( $index->attributes( 'type' ) ) {					// PRIMARY, UNIQUE, FULLTEXT, SPATIAL:					$sqlIndexText				.=	$this->_db->getEscaped( strtoupper( $index->attributes( 'type' ) ) ) . ' ';				}				$sqlIndexText					.=	'KEY ';				if ( $index->attributes( 'type' ) !== 'primary' ) {					$sqlIndexText				.=	$this->_db->NameQuote( $this->_prefixedName( $index, $colNamePrefix ) ) . ' ';				}				if ( $index->attributes( 'using' ) ) {					// BTREE, HASH, RTREE:					$sqlIndexText				.=	'USING ' . $this->_db->getEscaped( $index->attributes( 'using' ) ) . ' ';				}				$sqlIndexText					.=	'(' . implode( ', ', $indexColumns ) . ')';			}		}		return $sqlIndexText;	}	/**	 * Prefixes the $attribute of $column (or table or other xml element) with	 * $colNamePrefix if $column->attributes( 'nametype' ) == 'namesuffix' or 'nameprefix'	 * @access private	 *	 * @param  CBSimpleXMLElement  $column	 * @param  string              $colNamePrefix	 * @param  string              $attribute      	 * @param  string              $modifyingAttr	 * @return string	 */	function _prefixedName( &$column, $colNamePrefix, $attribute = 'name', $modifyingAttr = 'nametype' ) {		$colName								=	$column->attributes( $attribute );		$colNameType							=	$column->attributes( $modifyingAttr );		switch ( $colNameType ) {			case 'nameprefix':				$colName						.=	$colNamePrefix;								break;			case 'namesuffix':				$colName						=	$colNamePrefix . $colName;				break;					default:				break;		}		return $colName;	}	/**	 * Checks if all columns of a xml description of all tables of a database matches the database	 *	 * Warning: if ( $change && $strictlyColumns ) it will DROP not described columns !!!	 * @access private	 *	 * @param  CBSimpleXMLElement  $table	 * @param  string              $colNamePrefix    Prefix to add to all column names	 * @param  boolean             $change           FALSE: only check, TRUE: change database to match description (deleting columns if $strictlyColumns == true)	 * @param  boolean|null        $strictlyColumns  FALSE: allow for other columns, TRUE: doesn't allow for other columns, NULL: checks for attribute 'strict' in table	 * @return boolean             TRUE: matches, FALSE: don't match	 */	function checkXmlTableDescription( &$table, $colNamePrefix = '', $change = false, $strictlyColumns = false ) {		$isMatching								=	false;		if ( $table->name() == 'table' ) {			$tableName							=	$this->_prefixedName( $table, $colNamePrefix );			$columns							=&	$table->getElementByPath( 'columns' );			if ( $tableName && ( $columns !== false ) ) {				if ( $strictlyColumns === null ) {					$strictlyColumns			=	( $table->attributes( 'strict' ) == 'true' );				}				$isMatching						=	true;				$allColumns						=	$this->getAllTableColumns( $tableName );				if ( $allColumns === false ) {					// table doesn't exist:					if ( $change ) {						if ( $this->createTable( $table, $colNamePrefix ) ) {							$allColumns			=	$this->getAllTableColumns( $tableName );						} else {							$isMatching			=	false;						}					} else {						$this->_setError( sprintf( 'Table %s does not exist', $tableName ), null );						$isMatching				=	false;					}				} else {					// Table exists:					// 1) Check columns:					if ( $strictlyColumns ) {						$columnBefore			=	1;					} else {						$columnBefore			=	null;					}					foreach ( $columns->children() as $column ) {						if ( $column->name() == 'column' ) {							if ( ! $this->checkColumnExistsType( $tableName, $allColumns, $column, $colNamePrefix, $change ) ) {								if ( ( ! $change ) || ( ! $this->changeColumn( $tableName, $allColumns, $column, $colNamePrefix, $columnBefore ) ) ) {									$isMatching	=	false;								}							}							$columnBefore		=	$column;						}					}					if ( $strictlyColumns && ( $columns->attributes( 'strict' ) !== 'false' ) && ! $this->checkOtherColumnsExist( $tableName, $allColumns, $columns, $colNamePrefix, $change ) ) {						$isMatching				=	false;					}					// 2) Check indexes:					$indexes					=&	$table->getElementByPath( 'indexes' );					if ( $indexes !== false ) {						$allIndexes				=	$this->getAllTableIndexes( $tableName );						foreach ( $indexes->children() as $index ) {							if ( $index->name() == 'index' ) {								if ( ! $this->checkIndexExistsType( $tableName, $allIndexes, $index, $colNamePrefix, $change ) ) {									if ( ( ! $change ) || ( ! $this->changeIndex( $tableName, $allIndexes, $index, $colNamePrefix ) ) ) {										$isMatching	=	false;									}								}							}						}						if ( $strictlyColumns && ( $indexes->attributes( 'strict' ) !== 'false' ) && ! $this->checkOtherIndexesExist( $tableName, $allIndexes, $indexes, $colNamePrefix, $change ) ) {							$isMatching			=	false;						}					}				}				// 3) Now that indexed table is checked (exists or has been created), Check rows:				if ( $allColumns !== false ) {					$rows						=&	$table->getElementByPath( 'rows' );					if ( $rows !== false ) {						foreach ( $rows->children() as $row ) {							if ( $row->name() == 'row' ) {								$rowArray		=	null;								if ( ! $this->checkOrChangeRow( $tableName, $rows, $row, $allColumns, $colNamePrefix, $change ) ) {									$isMatching	=	false;								}							}						}						if ( $strictlyColumns && ( $rows->attributes( 'strict' ) !== 'false' ) && ! $this->checkOtherRowsExist( $tableName, $rows, $colNamePrefix, $change ) ) {							$isMatching			=	false;						}					}				}			}		}		return $isMatching;	}	/**	 * Checks if all columns of a xml description of all tables of a database matches the database	 *	 * Warning: removes columns tables and columns which would be added by the changes to XML !!!	 * @access private	 *	 * @param  CBSimpleXMLElement  $table	 * @param  string              $colNamePrefix    Prefix to add to all column names	 * @param  string              $change           'drop': uninstalls columns/tables	 * @param  boolean|null        $strictlyColumns  FALSE: allow for other columns, TRUE: doesn't allow for other columns, NULL: checks for attribute 'strict' in table	 * @return boolean             TRUE: matches, FALSE: don't match	 */	function dropXmlTableDescription( &$table, $colNamePrefix = '', $change = 'drop', $strictlyColumns = false ) {		$isMatching										=	false;		if ( $table->name() == 'table' ) {			$tableName									=	$this->_prefixedName( $table, $colNamePrefix );			$columns									=&	$table->getElementByPath( 'columns' );			if ( $tableName && ( $columns !== false ) ) {				if ( $strictlyColumns === null ) {					$strictlyColumns					=	( $table->attributes( 'strict' ) === 'true' );				}				$neverDropTable							=	( $table->attributes( 'drop' ) === 'never' );				$isMatching								=	true;				$allColumns								=	$this->getAllTableColumns( $tableName );				if ( $allColumns === false ) {					// table doesn't exist: do nothing				} else {					if ( $strictlyColumns && ( ! $neverDropTable ) ) {						if ( in_array( $tableName, array( '#__comprofiler', '#_users', '#__comprofiler_fields' ) ) ) {							// Safeguard against fatal error in XML file !							$errorMsg					=	sprintf( 'Fatal error: Trying to delete core CB table %s not allowed.', $tableName );							echo $errorMsg;							trigger_error( $errorMsg, E_USER_ERROR );							exit;						}						$this->dropTable( $tableName );					} else {						// 1) Drop rows:						$rows								=&	$table->getElementByPath( 'rows' );						if ( $rows !== false ) {							$neverDropRows					=	( $rows->attributes( 'drop' ) === 'never' );							if ( ! $neverDropRows ) {								$strictRows					=	( ( $rows->attributes( 'strict' ) === 'true' ) );								foreach ( $rows->children() as $row ) {									if ( $row->name() == 'row' ) {										$neverDropRow		=	( $row->attributes( 'drop' ) === 'never' );										if ( ( $strictRows && ! $neverDropRow ) ) {											if ( ! $this->dropRow( $tableName, $row, $colNamePrefix ) ) {												$isMatching	=	false;											}										}									}								}							}						}						// 2) Drop indexes:						$indexes							=&	$table->getElementByPath( 'indexes' );						if ( $indexes !== false ) {							$neverDropIndexes				=	( $indexes

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -