Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
6ed01e96
Commit
6ed01e96
authored
Jan 18, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DB cleanup.
parent
6dd495b6
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
119 additions
and
32 deletions
+119
-32
YiiBase.php
framework/YiiBase.php
+3
-2
Model.php
framework/base/Model.php
+2
-2
Theme.php
framework/base/Theme.php
+4
-2
Command.php
framework/db/Command.php
+37
-0
Connection.php
framework/db/Connection.php
+5
-4
QueryBuilder.php
framework/db/QueryBuilder.php
+10
-3
TableSchema.php
framework/db/TableSchema.php
+0
-4
Transaction.php
framework/db/Transaction.php
+3
-3
QueryBuilder.php
framework/db/mysql/QueryBuilder.php
+41
-0
Schema.php
framework/db/mysql/Schema.php
+3
-1
Request.php
framework/web/Request.php
+11
-11
No files found.
framework/YiiBase.php
View file @
6ed01e96
...
...
@@ -8,6 +8,7 @@
*/
use
yii\base\Exception
;
use
yii\base\InvalidCallException
;
/**
* Gets the application start timestamp.
...
...
@@ -345,7 +346,7 @@ class YiiBase
* @param string|array $config the configuration. It can be either a string representing the class name
* or an array representing the object configuration.
* @return mixed the created object
* @throws
\yii\base\Ba
dConfigException if the configuration is invalid.
* @throws
Invali
dConfigException if the configuration is invalid.
*/
public
static
function
createObject
(
$config
)
{
...
...
@@ -358,7 +359,7 @@ class YiiBase
$class
=
$config
[
'class'
];
unset
(
$config
[
'class'
]);
}
else
{
throw
new
\yii\base\BadConfig
Exception
(
'Object configuration must be an array containing a "class" element.'
);
throw
new
InvalidCall
Exception
(
'Object configuration must be an array containing a "class" element.'
);
}
if
(
!
class_exists
(
$class
,
false
))
{
...
...
framework/base/Model.php
View file @
6ed01e96
...
...
@@ -312,7 +312,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
* Creates validator objects based on the validation rules specified in [[rules()]].
* Unlike [[getValidators()]], each time this method is called, a new list of validators will be returned.
* @return Vector validators
* @throws
Ba
dConfigException if any validation rule configuration is invalid
* @throws
Invali
dConfigException if any validation rule configuration is invalid
*/
public
function
createValidators
()
{
...
...
@@ -324,7 +324,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
$validator
=
Validator
::
createValidator
(
$rule
[
1
],
$this
,
$rule
[
0
],
array_slice
(
$rule
,
2
));
$validators
->
add
(
$validator
);
}
else
{
throw
new
Ba
dConfigException
(
'Invalid validation rule: a rule must specify both attribute names and validator type.'
);
throw
new
Invali
dConfigException
(
'Invalid validation rule: a rule must specify both attribute names and validator type.'
);
}
}
return
$validators
;
...
...
framework/base/Theme.php
View file @
6ed01e96
...
...
@@ -9,6 +9,8 @@
namespace
yii\base
;
use
yii\base\InvalidConfigException
;
/**
* Theme represents an application theme.
*
...
...
@@ -25,12 +27,12 @@ class Theme extends ApplicationComponent
if
(
$this
->
basePath
!==
null
)
{
$this
->
basePath
=
\Yii
::
getAlias
(
$this
->
basePath
,
true
);
}
else
{
throw
new
Ba
dConfigException
(
"Theme.basePath must be set."
);
throw
new
Invali
dConfigException
(
"Theme.basePath must be set."
);
}
if
(
$this
->
baseUrl
!==
null
)
{
$this
->
baseUrl
=
\Yii
::
getAlias
(
$this
->
baseUrl
,
true
);
}
else
{
throw
new
Ba
dConfigException
(
"Theme.baseUrl must be set."
);
throw
new
Invali
dConfigException
(
"Theme.baseUrl must be set."
);
}
}
...
...
framework/db/Command.php
View file @
6ed01e96
...
...
@@ -9,6 +9,8 @@
namespace
yii\db
;
use
yii\base\NotSupportedException
;
/**
* Command represents a SQL statement to be executed against a database.
*
...
...
@@ -259,6 +261,7 @@ class Command extends \yii\base\Component
public
function
execute
(
$params
=
array
())
{
$sql
=
$this
->
getSql
();
$this
->
_params
=
array_merge
(
$this
->
_params
,
$params
);
if
(
$this
->
_params
===
array
())
{
$paramLog
=
''
;
...
...
@@ -268,6 +271,10 @@ class Command extends \yii\base\Component
\Yii
::
trace
(
"Executing SQL:
{
$sql
}{
$paramLog
}
"
,
__CLASS__
);
if
(
$sql
==
''
)
{
return
0
;
}
try
{
if
(
$this
->
connection
->
enableProfiling
)
{
\Yii
::
beginProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
...
...
@@ -707,4 +714,34 @@ class Command extends \yii\base\Component
$sql
=
$this
->
connection
->
getQueryBuilder
()
->
dropIndex
(
$name
,
$table
);
return
$this
->
setSql
(
$sql
);
}
/**
* Creates a SQL command for resetting the sequence value of a table's primary key.
* The sequence will be reset such that the primary key of the next new row inserted
* will have the specified value or 1.
* @param string $table the name of the table whose primary key sequence will be reset
* @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
* the next new row's primary key will have a value 1.
* @return Command the command object itself
* @throws NotSupportedException if this is not supported by the underlying DBMS
*/
public
function
resetSequence
(
$table
,
$value
=
null
)
{
$sql
=
$this
->
connection
->
getQueryBuilder
()
->
resetSequence
(
$table
,
$value
);
return
$this
->
setSql
(
$sql
);
}
/**
* Builds a SQL command for enabling or disabling integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema name of the tables. Defaults to empty string, meaning the current
* or default schema.
* @return Command the command object itself
* @throws NotSupportedException if this is not supported by the underlying DBMS
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
)
{
$sql
=
$this
->
connection
->
getQueryBuilder
()
->
checkIntegrity
(
$check
,
$schema
);
return
$this
->
setSql
(
$sql
);
}
}
framework/db/Connection.php
View file @
6ed01e96
...
...
@@ -9,7 +9,8 @@
namespace
yii\db
;
use
yii\base\BadConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\base\NotSupportedException
;
/**
* Connection represents a connection to a database via [PDO](http://www.php.net/manual/en/ref.pdo.php).
...
...
@@ -317,7 +318,7 @@ class Connection extends \yii\base\ApplicationComponent
{
if
(
$this
->
pdo
===
null
)
{
if
(
empty
(
$this
->
dsn
))
{
throw
new
Ba
dConfigException
(
'Connection.dsn cannot be empty.'
);
throw
new
Invali
dConfigException
(
'Connection.dsn cannot be empty.'
);
}
try
{
\Yii
::
trace
(
'Opening DB connection: '
.
$this
->
dsn
,
__CLASS__
);
...
...
@@ -426,7 +427,7 @@ class Connection extends \yii\base\ApplicationComponent
/**
* Returns the schema information for the database opened by this connection.
* @return Schema the schema information for the database opened by this connection.
* @throws
BadConfig
Exception if there is no support for the current driver type
* @throws
NotSupported
Exception if there is no support for the current driver type
*/
public
function
getSchema
()
{
...
...
@@ -439,7 +440,7 @@ class Connection extends \yii\base\ApplicationComponent
$this
->
_schema
->
connection
=
$this
;
return
$this
->
_schema
;
}
else
{
throw
new
BadConfig
Exception
(
"Connection does not support reading schema information for '
$driver
' DBMS."
);
throw
new
NotSupported
Exception
(
"Connection does not support reading schema information for '
$driver
' DBMS."
);
}
}
}
...
...
framework/db/QueryBuilder.php
View file @
6ed01e96
...
...
@@ -10,6 +10,7 @@
namespace
yii\db
;
use
yii\db\Exception
;
use
yii\base\NotSupportedException
;
/**
* QueryBuilder builds a SELECT SQL statement based on the specification given as a [[Query]] object.
...
...
@@ -385,24 +386,30 @@ class QueryBuilder extends \yii\base\Object
}
/**
*
Resets
the sequence value of a table's primary key.
*
Creates a SQL statement for resetting
the sequence value of a table's primary key.
* The sequence will be reset such that the primary key of the next new row inserted
* will have the specified value or 1.
* @param string $table the
table schema
whose primary key sequence will be reset
* @param string $table the
name of the table
whose primary key sequence will be reset
* @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
* the next new row's primary key will have a value 1.
* @return string the SQL statement for resetting sequence
* @throws NotSupportedException if this is not supported by the underlying DBMS
*/
public
function
resetSequence
(
$table
,
$value
=
null
)
{
throw
new
NotSupportedException
(
$this
->
connection
->
getDriverName
()
.
' does not support resetting sequence.'
);
}
/**
*
Enables or disables
integrity check.
*
Builds a SQL statement for enabling or disabling
integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @return string the SQL statement for checking integrity
* @throws NotSupportedException if this is not supported by the underlying DBMS
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
)
{
throw
new
NotSupportedException
(
$this
->
connection
->
getDriverName
()
.
' does not support enabling/disabling integrity check.'
);
}
/**
...
...
framework/db/TableSchema.php
View file @
6ed01e96
...
...
@@ -59,10 +59,6 @@ class TableSchema extends \yii\base\Object
* @var ColumnSchema[] column metadata of this table. Each array element is a [[ColumnSchema]] object, indexed by column names.
*/
public
$columns
=
array
();
/**
* @var string comment of this table
*/
public
$comment
;
/**
* Gets the named column metadata.
...
...
framework/db/Transaction.php
View file @
6ed01e96
...
...
@@ -9,7 +9,7 @@
namespace
yii\db
;
use
yii\base\
Ba
dConfigException
;
use
yii\base\
Invali
dConfigException
;
/**
* Transaction represents a DB transaction.
...
...
@@ -60,13 +60,13 @@ class Transaction extends \yii\base\Object
/**
* Begins a transaction.
* @throws
Ba
dConfigException if [[connection]] is null
* @throws
Invali
dConfigException if [[connection]] is null
*/
public
function
begin
()
{
if
(
!
$this
->
_active
)
{
if
(
$this
->
connection
===
null
)
{
throw
new
Ba
dConfigException
(
'Transaction.connection must be set.'
);
throw
new
Invali
dConfigException
(
'Transaction.connection must be set.'
);
}
\Yii
::
trace
(
'Starting transaction'
,
__CLASS__
);
$this
->
connection
->
open
();
...
...
framework/db/mysql/QueryBuilder.php
View file @
6ed01e96
...
...
@@ -10,6 +10,7 @@
namespace
yii\db\mysql
;
use
yii\db\Exception
;
use
yii\base\InvalidCallException
;
/**
* QueryBuilder is the query builder for MySQL databases.
...
...
@@ -88,4 +89,44 @@ class QueryBuilder extends \yii\db\QueryBuilder
return
'ALTER TABLE '
.
$this
->
connection
->
quoteTableName
(
$table
)
.
' DROP FOREIGN KEY '
.
$this
->
connection
->
quoteColumnName
(
$name
);
}
/**
* Creates a SQL statement for resetting the sequence value of a table's primary key.
* The sequence will be reset such that the primary key of the next new row inserted
* will have the specified value or 1.
* @param string $tableName the name of the table whose primary key sequence will be reset
* @param mixed $value the value for the primary key of the next new row inserted. If this is not set,
* the next new row's primary key will have a value 1.
* @return string the SQL statement for resetting sequence
* @throws InvalidCallException if the table does not exist or there is no sequence associated with the table.
*/
public
function
resetSequence
(
$tableName
,
$value
=
null
)
{
$table
=
$this
->
connection
->
getTableSchema
(
$tableName
);
if
(
$table
!==
null
&&
$table
->
sequenceName
!==
null
)
{
$tableName
=
$this
->
connection
->
quoteTableName
(
$tableName
);
if
(
$value
===
null
)
{
$key
=
reset
(
$table
->
primaryKey
);
$value
=
$this
->
connection
->
createCommand
(
"SELECT MAX(`
$key
`) FROM
$tableName
"
)
->
queryScalar
()
+
1
;
}
else
{
$value
=
(
int
)
$value
;
}
return
"ALTER TABLE
$tableName
AUTO_INCREMENT=
$value
"
;
}
elseif
(
$table
===
null
)
{
throw
new
InvalidCallException
(
"Table not found:
$tableName
"
);
}
else
{
throw
new
InvalidCallException
(
"There is not sequence associated with table '
$tableName
'.'"
);
}
}
/**
* Builds a SQL statement for enabling or disabling integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @return string the SQL statement for checking integrity
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
)
{
return
'SET FOREIGN_KEY_CHECKS='
.
(
$check
?
1
:
0
);
}
}
framework/db/mysql/Schema.php
View file @
6ed01e96
...
...
@@ -102,7 +102,7 @@ class Schema extends \yii\db\Schema
/**
* Resolves the table name and schema name (if any).
* @param
\yii\db\
TableSchema $table the table metadata object
* @param TableSchema $table the table metadata object
* @param string $name the table name
*/
protected
function
resolveTableNames
(
$table
,
$name
)
...
...
@@ -129,6 +129,8 @@ class Schema extends \yii\db\Schema
$column
->
allowNull
=
$info
[
'Null'
]
===
'YES'
;
$column
->
isPrimaryKey
=
strpos
(
$info
[
'Key'
],
'PRI'
)
!==
false
;
$column
->
autoIncrement
=
stripos
(
$info
[
'Extra'
],
'auto_increment'
)
!==
false
;
$column
->
comment
=
$info
[
'Comment'
];
$column
->
dbType
=
$info
[
'Type'
];
$column
->
unsigned
=
strpos
(
$column
->
dbType
,
'unsigned'
)
!==
false
;
...
...
framework/web/Request.php
View file @
6ed01e96
...
...
@@ -9,7 +9,7 @@
namespace
yii\web
;
use
\yii\base\
Ba
dConfigException
;
use
\yii\base\
Invali
dConfigException
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -357,7 +357,7 @@ class Request extends \yii\base\Request
* Returns the relative URL of the entry script.
* The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework.
* @return string the relative URL of the entry script.
* @throws
Ba
dConfigException if unable to determine the entry script URL
* @throws
Invali
dConfigException if unable to determine the entry script URL
*/
public
function
getScriptUrl
()
{
...
...
@@ -374,7 +374,7 @@ class Request extends \yii\base\Request
}
elseif
(
isset
(
$_SERVER
[
'DOCUMENT_ROOT'
])
&&
strpos
(
$_SERVER
[
'SCRIPT_FILENAME'
],
$_SERVER
[
'DOCUMENT_ROOT'
])
===
0
)
{
$this
->
_scriptUrl
=
str_replace
(
'\\'
,
'/'
,
str_replace
(
$_SERVER
[
'DOCUMENT_ROOT'
],
''
,
$_SERVER
[
'SCRIPT_FILENAME'
]));
}
else
{
throw
new
Ba
dConfigException
(
'Unable to determine the entry script URL.'
);
throw
new
Invali
dConfigException
(
'Unable to determine the entry script URL.'
);
}
}
return
$this
->
_scriptUrl
;
...
...
@@ -399,7 +399,7 @@ class Request extends \yii\base\Request
* The starting and ending slashes are both removed.
* @return string part of the request URL that is after the entry script and before the question mark.
* Note, the returned path info is decoded.
* @throws
Ba
dConfigException if the path info cannot be determined due to unexpected server configuration
* @throws
Invali
dConfigException if the path info cannot be determined due to unexpected server configuration
*/
public
function
getPathInfo
()
{
...
...
@@ -415,7 +415,7 @@ class Request extends \yii\base\Request
* The starting and ending slashes are both removed.
* @return string part of the request URL that is after the entry script and before the question mark.
* Note, the returned path info is decoded.
* @throws
Ba
dConfigException if the path info cannot be determined due to unexpected server configuration
* @throws
Invali
dConfigException if the path info cannot be determined due to unexpected server configuration
*/
protected
function
resolvePathInfo
()
{
...
...
@@ -479,7 +479,7 @@ class Request extends \yii\base\Request
* The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework.
* @return string the request URI portion for the currently requested URL.
* Note that the URI returned is URL-encoded.
* @throws
Ba
dConfigException if the request URI cannot be determined due to unusual server configuration
* @throws
Invali
dConfigException if the request URI cannot be determined due to unusual server configuration
*/
public
function
getRequestUri
()
{
...
...
@@ -496,7 +496,7 @@ class Request extends \yii\base\Request
* The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework.
* @return string|boolean the request URI portion for the currently requested URL.
* Note that the URI returned is URL-encoded.
* @throws
Ba
dConfigException if the request URI cannot be determined due to unusual server configuration
* @throws
Invali
dConfigException if the request URI cannot be determined due to unusual server configuration
*/
protected
function
resolveRequestUri
()
{
...
...
@@ -517,7 +517,7 @@ class Request extends \yii\base\Request
$requestUri
.=
'?'
.
$_SERVER
[
'QUERY_STRING'
];
}
}
else
{
throw
new
Ba
dConfigException
(
'Unable to determine the request URI.'
);
throw
new
Invali
dConfigException
(
'Unable to determine the request URI.'
);
}
return
$requestUri
;
}
...
...
@@ -599,7 +599,7 @@ class Request extends \yii\base\Request
/**
* Returns entry script file path.
* @return string entry script file path (processed w/ realpath())
* @throws
Ba
dConfigException if the entry script file path cannot be determined automatically.
* @throws
Invali
dConfigException if the entry script file path cannot be determined automatically.
*/
public
function
getScriptFile
()
{
...
...
@@ -615,13 +615,13 @@ class Request extends \yii\base\Request
* However, in some server configuration, this may not be correct or feasible.
* This setter is provided so that the entry script file path can be manually specified.
* @param string $value the entry script file path
* @throws
Ba
dConfigException if the provided entry script file path is invalid.
* @throws
Invali
dConfigException if the provided entry script file path is invalid.
*/
public
function
setScriptFile
(
$value
)
{
$this
->
_scriptFile
=
realpath
(
$value
);
if
(
$this
->
_scriptFile
===
false
||
!
is_file
(
$this
->
_scriptFile
))
{
throw
new
Ba
dConfigException
(
'Unable to determine the entry script file path.'
);
throw
new
Invali
dConfigException
(
'Unable to determine the entry script file path.'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment