mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 14:28:27 +08:00
Scrutinizer fixes (#18685)
* https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/filters/AccessRule.php?selectedLabels%5B0%5D=2&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/helpers/BaseFileHelper.php?selectedLabels%5B0%5D=2&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/base/Application.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/base/Module.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/web/MultipartFormDataParser.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/web/Session.php?selectedLabels%5B0%5D=7&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/base/Controller.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/MigrateController.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * Added vardocs, and small refactor * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/db/conditions/InConditionBuilder.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/db/Connection.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/db/mssql/QueryBuilder.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/log/Logger.php?selectedLabels%5B0%5D=6&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/BaseMigrateController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * Adding space between type * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/CacheController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/FixtureController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * https://scrutinizer-ci.com/g/yiisoft/yii2/issues/master/files/framework/console/controllers/MigrateController.php?selectedLabels%5B0%5D=18&selectedSeverities%5B0%5D=10&selectedSeverities%5B1%5D=5&orderField=path&order=asc&honorSelectedPaths=0 * Update framework/console/controllers/CacheController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/CacheController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/FixtureController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/FixtureController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/FixtureController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/FixtureController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/FixtureController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> * Update framework/console/controllers/FixtureController.php Co-authored-by: Alexander Makarov <sam@rmcreative.ru> Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
This commit is contained in:
@ -68,7 +68,7 @@ class BaseYii
|
|||||||
*/
|
*/
|
||||||
public static $classMap = [];
|
public static $classMap = [];
|
||||||
/**
|
/**
|
||||||
* @var \yii\console\Application|\yii\web\Application the application instance
|
* @var \yii\console\Application|\yii\web\Application|\yii\base\Application the application instance
|
||||||
*/
|
*/
|
||||||
public static $app;
|
public static $app;
|
||||||
/**
|
/**
|
||||||
@ -124,7 +124,7 @@ class BaseYii
|
|||||||
* @param string $alias the alias to be translated.
|
* @param string $alias the alias to be translated.
|
||||||
* @param bool $throwException whether to throw an exception if the given alias is invalid.
|
* @param bool $throwException whether to throw an exception if the given alias is invalid.
|
||||||
* If this is false and an invalid alias is given, false will be returned by this method.
|
* If this is false and an invalid alias is given, false will be returned by this method.
|
||||||
* @return string|bool the path corresponding to the alias, false if the root alias is not previously registered.
|
* @return string|false the path corresponding to the alias, false if the root alias is not previously registered.
|
||||||
* @throws InvalidArgumentException if the alias is invalid while $throwException is true.
|
* @throws InvalidArgumentException if the alias is invalid while $throwException is true.
|
||||||
* @see setAlias()
|
* @see setAlias()
|
||||||
*/
|
*/
|
||||||
@ -162,7 +162,7 @@ class BaseYii
|
|||||||
* A root alias is an alias that has been registered via [[setAlias()]] previously.
|
* A root alias is an alias that has been registered via [[setAlias()]] previously.
|
||||||
* If a given alias matches multiple root aliases, the longest one will be returned.
|
* If a given alias matches multiple root aliases, the longest one will be returned.
|
||||||
* @param string $alias the alias
|
* @param string $alias the alias
|
||||||
* @return string|bool the root alias, or false if no root alias is found
|
* @return string|false the root alias, or false if no root alias is found
|
||||||
*/
|
*/
|
||||||
public static function getRootAlias($alias)
|
public static function getRootAlias($alias)
|
||||||
{
|
{
|
||||||
|
@ -514,6 +514,7 @@ class Controller extends Component implements ViewContextInterface
|
|||||||
public function findLayoutFile($view)
|
public function findLayoutFile($view)
|
||||||
{
|
{
|
||||||
$module = $this->module;
|
$module = $this->module;
|
||||||
|
$layout = null;
|
||||||
if (is_string($this->layout)) {
|
if (is_string($this->layout)) {
|
||||||
$layout = $this->layout;
|
$layout = $this->layout;
|
||||||
} elseif ($this->layout === null) {
|
} elseif ($this->layout === null) {
|
||||||
@ -525,7 +526,7 @@ class Controller extends Component implements ViewContextInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($layout)) {
|
if ($layout === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ class Module extends ServiceLocator
|
|||||||
{
|
{
|
||||||
$path = Yii::getAlias($path);
|
$path = Yii::getAlias($path);
|
||||||
$p = strncmp($path, 'phar://', 7) === 0 ? $path : realpath($path);
|
$p = strncmp($path, 'phar://', 7) === 0 ? $path : realpath($path);
|
||||||
if ($p !== false && is_dir($p)) {
|
if (is_string($p) && is_dir($p)) {
|
||||||
$this->_basePath = $p;
|
$this->_basePath = $p;
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException("The directory does not exist: $path");
|
throw new InvalidArgumentException("The directory does not exist: $path");
|
||||||
|
@ -132,7 +132,7 @@ class AttributeTypecastBehavior extends Behavior
|
|||||||
* 'price' => 'float',
|
* 'price' => 'float',
|
||||||
* 'is_active' => 'boolean',
|
* 'is_active' => 'boolean',
|
||||||
* 'date' => function ($value) {
|
* 'date' => function ($value) {
|
||||||
* return ($value instanceof \DateTime) ? $value->getTimestamp(): (int)$value;
|
* return ($value instanceof \DateTime) ? $value->getTimestamp(): (int) $value;
|
||||||
* },
|
* },
|
||||||
* ]
|
* ]
|
||||||
* ```
|
* ```
|
||||||
|
@ -587,9 +587,7 @@ abstract class BaseMigrateController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionNew($limit = 10)
|
public function actionNew($limit = 10)
|
||||||
{
|
{
|
||||||
if ($limit === 'all') {
|
if ($limit !== 'all') {
|
||||||
$limit = null;
|
|
||||||
} else {
|
|
||||||
$limit = (int) $limit;
|
$limit = (int) $limit;
|
||||||
if ($limit < 1) {
|
if ($limit < 1) {
|
||||||
throw new Exception('The limit must be greater than 0.');
|
throw new Exception('The limit must be greater than 0.');
|
||||||
@ -602,7 +600,7 @@ abstract class BaseMigrateController extends Controller
|
|||||||
$this->stdout("No new migrations found. Your system is up-to-date.\n", Console::FG_GREEN);
|
$this->stdout("No new migrations found. Your system is up-to-date.\n", Console::FG_GREEN);
|
||||||
} else {
|
} else {
|
||||||
$n = count($migrations);
|
$n = count($migrations);
|
||||||
if ($limit && $n > $limit) {
|
if ($limit !== 'all' && $n > $limit) {
|
||||||
$migrations = array_slice($migrations, 0, $limit);
|
$migrations = array_slice($migrations, 0, $limit);
|
||||||
$this->stdout("Showing $limit out of $n new " . ($n === 1 ? 'migration' : 'migrations') . ":\n", Console::FG_YELLOW);
|
$this->stdout("Showing $limit out of $n new " . ($n === 1 ? 'migration' : 'migrations') . ":\n", Console::FG_YELLOW);
|
||||||
} else {
|
} else {
|
||||||
|
@ -84,11 +84,11 @@ class CacheController extends Controller
|
|||||||
$foundCaches = array_keys($caches);
|
$foundCaches = array_keys($caches);
|
||||||
$notFoundCaches = array_diff($cachesInput, array_keys($caches));
|
$notFoundCaches = array_diff($cachesInput, array_keys($caches));
|
||||||
|
|
||||||
if ($notFoundCaches) {
|
if ($notFoundCaches !== []) {
|
||||||
$this->notifyNotFoundCaches($notFoundCaches);
|
$this->notifyNotFoundCaches($notFoundCaches);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$foundCaches) {
|
if ($foundCaches === []) {
|
||||||
$this->notifyNoCachesFound();
|
$this->notifyNoCachesFound();
|
||||||
return ExitCode::OK;
|
return ExitCode::OK;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ class FixtureController extends Controller
|
|||||||
$foundFixtures = $this->findFixtures($fixtures);
|
$foundFixtures = $this->findFixtures($fixtures);
|
||||||
$notFoundFixtures = array_diff($fixtures, $foundFixtures);
|
$notFoundFixtures = array_diff($fixtures, $foundFixtures);
|
||||||
|
|
||||||
if ($notFoundFixtures) {
|
if ($notFoundFixtures !== []) {
|
||||||
$this->notifyNotFound($notFoundFixtures);
|
$this->notifyNotFound($notFoundFixtures);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -138,7 +138,7 @@ class FixtureController extends Controller
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$fixturesToLoad) {
|
if ($fixturesToLoad === []) {
|
||||||
$this->notifyNothingToLoad($foundFixtures, $except);
|
$this->notifyNothingToLoad($foundFixtures, $except);
|
||||||
return ExitCode::OK;
|
return ExitCode::OK;
|
||||||
}
|
}
|
||||||
@ -198,23 +198,23 @@ class FixtureController extends Controller
|
|||||||
$foundFixtures = $this->findFixtures($fixtures);
|
$foundFixtures = $this->findFixtures($fixtures);
|
||||||
$notFoundFixtures = array_diff($fixtures, $foundFixtures);
|
$notFoundFixtures = array_diff($fixtures, $foundFixtures);
|
||||||
|
|
||||||
if ($notFoundFixtures) {
|
if ($notFoundFixtures !== []) {
|
||||||
$this->notifyNotFound($notFoundFixtures);
|
$this->notifyNotFound($notFoundFixtures);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$foundFixtures = $this->findFixtures();
|
$foundFixtures = $this->findFixtures();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fixturesToUnload = array_diff($foundFixtures, $except);
|
if ($foundFixtures === []) {
|
||||||
|
|
||||||
if (!$foundFixtures) {
|
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
'No files were found for: "' . implode(', ', $fixturesInput) . "\".\n" .
|
'No files were found for: "' . implode(', ', $fixturesInput) . "\".\n" .
|
||||||
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . '".'
|
"Check that files exist under fixtures path: \n\"" . $this->getFixturePath() . '".'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$fixturesToUnload) {
|
$fixturesToUnload = array_diff($foundFixtures, $except);
|
||||||
|
|
||||||
|
if ($fixturesToUnload === []) {
|
||||||
$this->notifyNothingToUnload($foundFixtures, $except);
|
$this->notifyNothingToUnload($foundFixtures, $except);
|
||||||
return ExitCode::OK;
|
return ExitCode::OK;
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ class FixtureController extends Controller
|
|||||||
|
|
||||||
$fixtures = $this->getFixturesConfig(array_merge($this->globalFixtures, $fixturesToUnload));
|
$fixtures = $this->getFixturesConfig(array_merge($this->globalFixtures, $fixturesToUnload));
|
||||||
|
|
||||||
if (!$fixtures) {
|
if ($fixtures === []) {
|
||||||
throw new Exception('No fixtures were found in namespace: ' . $this->namespace . '".');
|
throw new Exception('No fixtures were found in namespace: ' . $this->namespace . '".');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ class HelpController extends Controller
|
|||||||
}
|
}
|
||||||
if (is_bool($defaultValue)) {
|
if (is_bool($defaultValue)) {
|
||||||
// show as integer to avoid confusion
|
// show as integer to avoid confusion
|
||||||
$defaultValue = (int)$defaultValue;
|
$defaultValue = (int) $defaultValue;
|
||||||
}
|
}
|
||||||
if (is_string($defaultValue)) {
|
if (is_string($defaultValue)) {
|
||||||
$defaultValue = "'" . $defaultValue . "'";
|
$defaultValue = "'" . $defaultValue . "'";
|
||||||
|
@ -301,11 +301,9 @@ class MigrateController extends BaseMigrateController
|
|||||||
|
|
||||||
// First drop all foreign keys,
|
// First drop all foreign keys,
|
||||||
foreach ($schemas as $schema) {
|
foreach ($schemas as $schema) {
|
||||||
if ($schema->foreignKeys) {
|
foreach ($schema->foreignKeys as $name => $foreignKey) {
|
||||||
foreach ($schema->foreignKeys as $name => $foreignKey) {
|
$db->createCommand()->dropForeignKey($name, $schema->name)->execute();
|
||||||
$db->createCommand()->dropForeignKey($name, $schema->name)->execute();
|
$this->stdout("Foreign key $name dropped.\n");
|
||||||
$this->stdout("Foreign key $name dropped.\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,10 +578,10 @@ class MigrateController extends BaseMigrateController
|
|||||||
*/
|
*/
|
||||||
protected function splitFieldIntoChunks($field)
|
protected function splitFieldIntoChunks($field)
|
||||||
{
|
{
|
||||||
$hasDoubleQuotes = false;
|
$originalDefaultValue = null;
|
||||||
|
$defaultValue = null;
|
||||||
preg_match_all('/defaultValue\(["\'].*?:?.*?["\']\)/', $field, $matches, PREG_SET_ORDER, 0);
|
preg_match_all('/defaultValue\(["\'].*?:?.*?["\']\)/', $field, $matches, PREG_SET_ORDER, 0);
|
||||||
if (isset($matches[0][0])) {
|
if (isset($matches[0][0])) {
|
||||||
$hasDoubleQuotes = true;
|
|
||||||
$originalDefaultValue = $matches[0][0];
|
$originalDefaultValue = $matches[0][0];
|
||||||
$defaultValue = str_replace(':', '{{colon}}', $originalDefaultValue);
|
$defaultValue = str_replace(':', '{{colon}}', $originalDefaultValue);
|
||||||
$field = str_replace($originalDefaultValue, $defaultValue, $field);
|
$field = str_replace($originalDefaultValue, $defaultValue, $field);
|
||||||
@ -591,7 +589,7 @@ class MigrateController extends BaseMigrateController
|
|||||||
|
|
||||||
$chunks = preg_split('/\s?:\s?/', $field);
|
$chunks = preg_split('/\s?:\s?/', $field);
|
||||||
|
|
||||||
if (is_array($chunks) && $hasDoubleQuotes) {
|
if (is_array($chunks) && $defaultValue !== null && $originalDefaultValue !== null) {
|
||||||
foreach ($chunks as $key => $chunk) {
|
foreach ($chunks as $key => $chunk) {
|
||||||
$chunks[$key] = str_replace($defaultValue, $originalDefaultValue, $chunk);
|
$chunks[$key] = str_replace($defaultValue, $originalDefaultValue, $chunk);
|
||||||
}
|
}
|
||||||
|
@ -1294,6 +1294,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
|||||||
*/
|
*/
|
||||||
public function link($name, $model, $extraColumns = [])
|
public function link($name, $model, $extraColumns = [])
|
||||||
{
|
{
|
||||||
|
/* @var $relation ActiveQueryInterface|ActiveQuery */
|
||||||
$relation = $this->getRelation($name);
|
$relation = $this->getRelation($name);
|
||||||
|
|
||||||
if ($relation->via !== null) {
|
if ($relation->via !== null) {
|
||||||
@ -1330,16 +1331,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
|||||||
$record->insert(false);
|
$record->insert(false);
|
||||||
} else {
|
} else {
|
||||||
/* @var $viaTable string */
|
/* @var $viaTable string */
|
||||||
static::getDb()->createCommand()
|
static::getDb()->createCommand()->insert($viaTable, $columns)->execute();
|
||||||
->insert($viaTable, $columns)->execute();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$p1 = $model->isPrimaryKey(array_keys($relation->link));
|
$p1 = $model->isPrimaryKey(array_keys($relation->link));
|
||||||
$p2 = static::isPrimaryKey(array_values($relation->link));
|
$p2 = static::isPrimaryKey(array_values($relation->link));
|
||||||
if ($p1 && $p2) {
|
if ($p1 && $p2) {
|
||||||
if ($this->getIsNewRecord() && $model->getIsNewRecord()) {
|
if ($this->getIsNewRecord()) {
|
||||||
throw new InvalidCallException('Unable to link models: at most one model can be newly created.');
|
if ($model->getIsNewRecord()) {
|
||||||
} elseif ($this->getIsNewRecord()) {
|
throw new InvalidCallException('Unable to link models: at most one model can be newly created.');
|
||||||
|
}
|
||||||
$this->bindModels(array_flip($relation->link), $this, $model);
|
$this->bindModels(array_flip($relation->link), $this, $model);
|
||||||
} else {
|
} else {
|
||||||
$this->bindModels($relation->link, $model, $this);
|
$this->bindModels($relation->link, $model, $this);
|
||||||
@ -1492,6 +1493,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
|||||||
*/
|
*/
|
||||||
public function unlinkAll($name, $delete = false)
|
public function unlinkAll($name, $delete = false)
|
||||||
{
|
{
|
||||||
|
/* @var $relation ActiveQueryInterface|ActiveQuery */
|
||||||
$relation = $this->getRelation($name);
|
$relation = $this->getRelation($name);
|
||||||
|
|
||||||
if ($relation->via !== null) {
|
if ($relation->via !== null) {
|
||||||
|
@ -694,20 +694,24 @@ class Connection extends Component
|
|||||||
{
|
{
|
||||||
$pdoClass = $this->pdoClass;
|
$pdoClass = $this->pdoClass;
|
||||||
if ($pdoClass === null) {
|
if ($pdoClass === null) {
|
||||||
$pdoClass = 'PDO';
|
$driver = null;
|
||||||
if ($this->_driverName !== null) {
|
if ($this->_driverName !== null) {
|
||||||
$driver = $this->_driverName;
|
$driver = $this->_driverName;
|
||||||
} elseif (($pos = strpos($this->dsn, ':')) !== false) {
|
} elseif (($pos = strpos($this->dsn, ':')) !== false) {
|
||||||
$driver = strtolower(substr($this->dsn, 0, $pos));
|
$driver = strtolower(substr($this->dsn, 0, $pos));
|
||||||
}
|
}
|
||||||
if (isset($driver)) {
|
switch ($driver) {
|
||||||
if ($driver === 'mssql') {
|
case 'mssql':
|
||||||
$pdoClass = 'yii\db\mssql\PDO';
|
$pdoClass = 'yii\db\mssql\PDO';
|
||||||
} elseif ($driver === 'dblib') {
|
break;
|
||||||
|
case 'dblib':
|
||||||
$pdoClass = 'yii\db\mssql\DBLibPDO';
|
$pdoClass = 'yii\db\mssql\DBLibPDO';
|
||||||
} elseif ($driver === 'sqlsrv') {
|
break;
|
||||||
|
case 'sqlsrv':
|
||||||
$pdoClass = 'yii\db\mssql\SqlsrvPDO';
|
$pdoClass = 'yii\db\mssql\SqlsrvPDO';
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
$pdoClass = 'PDO';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,18 +54,16 @@ class InConditionBuilder implements ExpressionBuilderInterface
|
|||||||
if (is_array($column)) {
|
if (is_array($column)) {
|
||||||
if (count($column) > 1) {
|
if (count($column) > 1) {
|
||||||
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
||||||
} else {
|
|
||||||
$column = reset($column);
|
|
||||||
}
|
}
|
||||||
|
$column = reset($column);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($column instanceof \Traversable) {
|
if ($column instanceof \Traversable) {
|
||||||
if (iterator_count($column) > 1) {
|
if (iterator_count($column) > 1) {
|
||||||
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
return $this->buildCompositeInCondition($operator, $column, $values, $params);
|
||||||
} else {
|
|
||||||
$column->rewind();
|
|
||||||
$column = $column->current();
|
|
||||||
}
|
}
|
||||||
|
$column->rewind();
|
||||||
|
$column = $column->current();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($values)) {
|
if (is_array($values)) {
|
||||||
@ -74,6 +72,8 @@ class InConditionBuilder implements ExpressionBuilderInterface
|
|||||||
$rawValues = $this->getRawValuesFromTraversableObject($values);
|
$rawValues = $this->getRawValuesFromTraversableObject($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nullCondition = null;
|
||||||
|
$nullConditionOperator = null;
|
||||||
if (isset($rawValues) && in_array(null, $rawValues, true)) {
|
if (isset($rawValues) && in_array(null, $rawValues, true)) {
|
||||||
$nullCondition = $this->getNullCondition($operator, $column);
|
$nullCondition = $this->getNullCondition($operator, $column);
|
||||||
$nullConditionOperator = $operator === 'IN' ? 'OR' : 'AND';
|
$nullConditionOperator = $operator === 'IN' ? 'OR' : 'AND';
|
||||||
@ -81,7 +81,7 @@ class InConditionBuilder implements ExpressionBuilderInterface
|
|||||||
|
|
||||||
$sqlValues = $this->buildValues($expression, $values, $params);
|
$sqlValues = $this->buildValues($expression, $values, $params);
|
||||||
if (empty($sqlValues)) {
|
if (empty($sqlValues)) {
|
||||||
if (!isset($nullCondition)) {
|
if ($nullCondition === null) {
|
||||||
return $operator === 'IN' ? '0=1' : '';
|
return $operator === 'IN' ? '0=1' : '';
|
||||||
}
|
}
|
||||||
return $nullCondition;
|
return $nullCondition;
|
||||||
@ -97,7 +97,9 @@ class InConditionBuilder implements ExpressionBuilderInterface
|
|||||||
$sql = $column . $operator . reset($sqlValues);
|
$sql = $column . $operator . reset($sqlValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isset($nullCondition) ? sprintf('%s %s %s', $sql, $nullConditionOperator, $nullCondition) : $sql;
|
return $nullCondition !== null && $nullConditionOperator !== null
|
||||||
|
? sprintf('%s %s %s', $sql, $nullConditionOperator, $nullCondition)
|
||||||
|
: $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,6 +11,7 @@ use yii\base\InvalidArgumentException;
|
|||||||
use yii\base\NotSupportedException;
|
use yii\base\NotSupportedException;
|
||||||
use yii\db\Constraint;
|
use yii\db\Constraint;
|
||||||
use yii\db\Expression;
|
use yii\db\Expression;
|
||||||
|
use yii\db\TableSchema;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QueryBuilder is the query builder for MS SQL Server databases (version 2008 and above).
|
* QueryBuilder is the query builder for MS SQL Server databases (version 2008 and above).
|
||||||
@ -483,10 +484,11 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
|||||||
$version2005orLater = version_compare($this->db->getSchema()->getServerVersion(), '9', '>=');
|
$version2005orLater = version_compare($this->db->getSchema()->getServerVersion(), '9', '>=');
|
||||||
|
|
||||||
list($names, $placeholders, $values, $params) = $this->prepareInsertValues($table, $columns, $params);
|
list($names, $placeholders, $values, $params) = $this->prepareInsertValues($table, $columns, $params);
|
||||||
|
$cols = [];
|
||||||
|
$columns = [];
|
||||||
if ($version2005orLater) {
|
if ($version2005orLater) {
|
||||||
|
/* @var $schema TableSchema */
|
||||||
$schema = $this->db->getTableSchema($table);
|
$schema = $this->db->getTableSchema($table);
|
||||||
$cols = [];
|
|
||||||
$columns = [];
|
|
||||||
foreach ($schema->columns as $column) {
|
foreach ($schema->columns as $column) {
|
||||||
if ($column->isComputed) {
|
if ($column->isComputed) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -394,9 +394,9 @@ SQL;
|
|||||||
}
|
}
|
||||||
if (!empty($matches[2])) {
|
if (!empty($matches[2])) {
|
||||||
$values = explode(',', $matches[2]);
|
$values = explode(',', $matches[2]);
|
||||||
$column->size = $column->precision = (int)$values[0];
|
$column->size = $column->precision = (int) $values[0];
|
||||||
if (isset($values[1])) {
|
if (isset($values[1])) {
|
||||||
$column->scale = (int)$values[1];
|
$column->scale = (int) $values[1];
|
||||||
}
|
}
|
||||||
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
|
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
|
||||||
$column->type = 'boolean';
|
$column->type = 'boolean';
|
||||||
|
@ -607,7 +607,7 @@ SQL;
|
|||||||
$column->precision = $info['numeric_precision'];
|
$column->precision = $info['numeric_precision'];
|
||||||
$column->scale = $info['numeric_scale'];
|
$column->scale = $info['numeric_scale'];
|
||||||
$column->size = $info['size'] === null ? null : (int) $info['size'];
|
$column->size = $info['size'] === null ? null : (int) $info['size'];
|
||||||
$column->dimension = (int)$info['dimension'];
|
$column->dimension = (int) $info['dimension'];
|
||||||
// pg_get_serial_sequence() doesn't track DEFAULT value change. GENERATED BY IDENTITY columns always have null default value
|
// pg_get_serial_sequence() doesn't track DEFAULT value change. GENERATED BY IDENTITY columns always have null default value
|
||||||
if (isset($column->defaultValue) && preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $column->defaultValue) === 1) {
|
if (isset($column->defaultValue) && preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $column->defaultValue) === 1) {
|
||||||
$column->sequenceName = preg_replace(['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'], '', $column->defaultValue);
|
$column->sequenceName = preg_replace(['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'], '', $column->defaultValue);
|
||||||
|
@ -66,10 +66,10 @@ class AccessRule extends Component
|
|||||||
* @see $roleParams
|
* @see $roleParams
|
||||||
*/
|
*/
|
||||||
public $roles;
|
public $roles;
|
||||||
/**
|
/**
|
||||||
* @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
|
* @var array list of RBAC (Role-Based Access Control) permissions that this rules applies to.
|
||||||
* [[User::can()]] will be called to check access.
|
* [[User::can()]] will be called to check access.
|
||||||
*
|
*
|
||||||
* If this property is not set or empty, it means this rule applies regardless of permissions.
|
* If this property is not set or empty, it means this rule applies regardless of permissions.
|
||||||
* @since 2.0.12
|
* @since 2.0.12
|
||||||
* @see $roles
|
* @see $roles
|
||||||
@ -264,16 +264,17 @@ class AccessRule extends Component
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
foreach ($this->ips as $rule) {
|
foreach ($this->ips as $rule) {
|
||||||
if ($rule === '*' ||
|
if (
|
||||||
$rule === $ip ||
|
$rule === '*'
|
||||||
(
|
|| $rule === $ip
|
||||||
$ip !== null &&
|
|| (
|
||||||
($pos = strpos($rule, '*')) !== false &&
|
$ip !== null
|
||||||
strncmp($ip, $rule, $pos) === 0
|
&& ($pos = strpos($rule, '*')) !== false
|
||||||
) ||
|
&& strncmp($ip, $rule, $pos) === 0
|
||||||
(
|
)
|
||||||
($pos = strpos($rule, '/')) !== false &&
|
|| (
|
||||||
IpHelper::inRange($ip, $rule) === true
|
strpos($rule, '/') !== false
|
||||||
|
&& IpHelper::inRange($ip, $rule) === true
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -596,19 +596,15 @@ class BaseFileHelper
|
|||||||
|
|
||||||
$path = str_replace('\\', '/', $path);
|
$path = str_replace('\\', '/', $path);
|
||||||
|
|
||||||
if (!empty($options['except'])) {
|
if (
|
||||||
if (($except = self::lastExcludeMatchingFromList($options['basePath'], $path, $options['except'])) !== null) {
|
!empty($options['except'])
|
||||||
return $except['flags'] & self::PATTERN_NEGATIVE;
|
&& ($except = self::lastExcludeMatchingFromList($options['basePath'], $path, $options['except'])) !== null
|
||||||
}
|
) {
|
||||||
|
return $except['flags'] & self::PATTERN_NEGATIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($options['only']) && !is_dir($path)) {
|
if (!empty($options['only']) && !is_dir($path)) {
|
||||||
if (($except = self::lastExcludeMatchingFromList($options['basePath'], $path, $options['only'])) !== null) {
|
return self::lastExcludeMatchingFromList($options['basePath'], $path, $options['only']) !== null;
|
||||||
// don't check PATTERN_NEGATIVE since those entries are not prefixed with !
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -218,11 +218,15 @@ class Logger extends Component
|
|||||||
return $timings;
|
return $timings;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($timings as $i => $timing) {
|
foreach ($timings as $outerIndex => $outerTimingItem) {
|
||||||
|
$currentIndex = $outerIndex;
|
||||||
$matched = empty($categories);
|
$matched = empty($categories);
|
||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
$prefix = rtrim($category, '*');
|
$prefix = rtrim($category, '*');
|
||||||
if (($timing['category'] === $category || $prefix !== $category) && strpos($timing['category'], $prefix) === 0) {
|
if (
|
||||||
|
($outerTimingItem['category'] === $category || $prefix !== $category)
|
||||||
|
&& strpos($outerTimingItem['category'], $prefix) === 0
|
||||||
|
) {
|
||||||
$matched = true;
|
$matched = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -231,8 +235,12 @@ class Logger extends Component
|
|||||||
if ($matched) {
|
if ($matched) {
|
||||||
foreach ($excludeCategories as $category) {
|
foreach ($excludeCategories as $category) {
|
||||||
$prefix = rtrim($category, '*');
|
$prefix = rtrim($category, '*');
|
||||||
foreach ($timings as $i => $timing) {
|
foreach ($timings as $innerIndex => $innerTimingItem) {
|
||||||
if (($timing['category'] === $category || $prefix !== $category) && strpos($timing['category'], $prefix) === 0) {
|
$currentIndex = $innerIndex;
|
||||||
|
if (
|
||||||
|
($innerTimingItem['category'] === $category || $prefix !== $category)
|
||||||
|
&& strpos($innerTimingItem['category'], $prefix) === 0
|
||||||
|
) {
|
||||||
$matched = false;
|
$matched = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -241,7 +249,7 @@ class Logger extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$matched) {
|
if (!$matched) {
|
||||||
unset($timings[$i]);
|
unset($timings[$currentIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ class MultipartFormDataParser extends BaseObject implements RequestParserInterfa
|
|||||||
public function getUploadFileMaxCount()
|
public function getUploadFileMaxCount()
|
||||||
{
|
{
|
||||||
if ($this->_uploadFileMaxCount === null) {
|
if ($this->_uploadFileMaxCount === null) {
|
||||||
$this->_uploadFileMaxCount = ini_get('max_file_uploads');
|
$this->_uploadFileMaxCount = (int)ini_get('max_file_uploads');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_uploadFileMaxCount;
|
return $this->_uploadFileMaxCount;
|
||||||
|
@ -105,7 +105,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
|
|||||||
*/
|
*/
|
||||||
private $_cookieParams = ['httponly' => true];
|
private $_cookieParams = ['httponly' => true];
|
||||||
/**
|
/**
|
||||||
* @var $frozenSessionData array|null is used for saving session between recreations due to session parameters update.
|
* @var array|null is used for saving session between recreations due to session parameters update.
|
||||||
*/
|
*/
|
||||||
private $frozenSessionData;
|
private $frozenSessionData;
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ SQL;
|
|||||||
}
|
}
|
||||||
$this->assertEquals($numericCol, $row['numeric_col']);
|
$this->assertEquals($numericCol, $row['numeric_col']);
|
||||||
if ($this->driverName === 'mysql' || $this->driverName === 'oci' || (\defined('HHVM_VERSION') && \in_array($this->driverName, ['sqlite', 'pgsql']))) {
|
if ($this->driverName === 'mysql' || $this->driverName === 'oci' || (\defined('HHVM_VERSION') && \in_array($this->driverName, ['sqlite', 'pgsql']))) {
|
||||||
$this->assertEquals($boolCol, (int)$row['bool_col']);
|
$this->assertEquals($boolCol, (int) $row['bool_col']);
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals($boolCol, $row['bool_col']);
|
$this->assertEquals($boolCol, $row['bool_col']);
|
||||||
}
|
}
|
||||||
|
@ -606,7 +606,7 @@ abstract class QueryTest extends DatabaseTestCase
|
|||||||
->where($whereCondition)
|
->where($whereCondition)
|
||||||
->count('*', $db);
|
->count('*', $db);
|
||||||
if (is_numeric($result)) {
|
if (is_numeric($result)) {
|
||||||
$result = (int)$result;
|
$result = (int) $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
Reference in New Issue
Block a user