Skip to content

Commit

Permalink
Merge pull request yiisoft#20058 from terabytesoftw/sinc-to-master-br…
Browse files Browse the repository at this point in the history
…anch

Sinc to master branch.
  • Loading branch information
bizley authored Nov 1, 2023
2 parents 203952f + 5f5745b commit 0294cf4
Show file tree
Hide file tree
Showing 16 changed files with 1,122 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Autodetect text files
* text=auto
* text=auto eol=lf

# ...Unless the name matches the following overriding patterns

Expand Down
250 changes: 126 additions & 124 deletions docs/internals-fa/core-code-style.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ Yii Framework 2 Change Log
2.2 under development
------------------------

- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw)
- Chg #19902: Remove support for CUBRID (mtangoo)
- Chg #19891: Remove XCache and ZendDataCache support (mtangoo)


2.0.50 under development
------------------------

- Bug #20045: Fix type `boolean` in `MySQL` (terabytesoftw)
- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw)
- Bug #20005: Fix `yii\console\controllers\ServeController` to specify the router script (terabytesoftw)
- Bug #19060: Fix `yii\widgets\Menu` bug when using Closure for active item and adding additional tests in `tests\framework\widgets\MenuTest` (atrandafir)
- Bug #13920: Fixed erroneous validation for specific cases (tim-fischer-maschinensucher)
- Bug #19927: Fixed `console\controllers\MessageController` when saving translations to database: fixed FK error when adding new string and language at the same time, checking/regenerating all missing messages and dropping messages for unused languages (atrandafir)
- Bug #20002: Fixed superfluous query on HEAD request in serializer (xicond)
- Enh #12743: Added new methods `BaseActiveRecord::loadRelations()` and `BaseActiveRecord::loadRelationsFor()` to eager load related models for existing primary model instances (PowerGamer1)
- Enh #20030: Improve performance of handling `ErrorHandler::$memoryReserveSize` (antonshevelev, rob006)
- Enh #20042: Add empty array check to `ActiveQueryTrait::findWith()` (renkas)
- Enh #20032: Added `yii\helpers\BaseStringHelper::mask()` method for string masking with multibyte support (salehhashemi1992)
- Enh #20034: Added `yii\helpers\BaseStringHelper::findBetween()` to retrieve a substring that lies between two strings (salehhashemi1992)


2.0.49.2 October 12, 2023
-------------------------
Expand Down
2 changes: 1 addition & 1 deletion framework/base/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function register()
set_error_handler([$this, 'handleError']);
}
if ($this->memoryReserveSize > 0) {
$this->_memoryReserve = str_pad('', $this->memoryReserveSize, 'x');
$this->_memoryReserve = str_repeat('x', $this->memoryReserveSize);
}
// to restore working directory in shutdown handler
if (PHP_SAPI !== 'cli') {
Expand Down
4 changes: 4 additions & 0 deletions framework/db/ActiveQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ protected function createModels($rows)
*/
public function findWith($with, &$models)
{
if (empty($models)) {
return;
}

$primaryModel = reset($models);
if (!$primaryModel instanceof ActiveRecordInterface) {
/* @var $modelClass ActiveRecordInterface */
Expand Down
30 changes: 29 additions & 1 deletion framework/db/mssql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ protected function resolveTableNames($table, $name)
*/
protected function loadColumnSchema($info)
{
$isVersion2017orLater = version_compare($this->db->getSchema()->getServerVersion(), '14', '>=');
$column = $this->createColumnSchema();

$column->name = $info['column_name'];
Expand All @@ -395,7 +396,7 @@ protected function loadColumnSchema($info)
$column->type = $this->typeMap[$type];
}

if ($type === 'bit') {
if ($isVersion2017orLater && $type === 'bit') {
$column->type = 'boolean';
}

Expand All @@ -406,6 +407,10 @@ protected function loadColumnSchema($info)
if (isset($values[1])) {
$column->scale = (int) $values[1];
}

if ($isVersion2017orLater === false) {
$column->type = $this->booleanTypeLegacy($column->size, $type);
}
}
}

Expand Down Expand Up @@ -811,4 +816,27 @@ public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length, $this->db]);
}

/**
* Assigns a type boolean for the column type bit, for legacy versions of MSSQL.
*
* @param int $size column size.
* @param string $type column type.
*
* @return string column type.
*/
private function booleanTypeLegacy($size, $type)
{
if ($size === 1 && ($type === 'tinyint' || $type === 'bit')) {
return 'boolean';
} elseif ($type === 'bit') {
if ($size > 32) {
return 'bigint';
} elseif ($size === 32) {
return 'integer';
}
}

return $type;
}
}
2 changes: 1 addition & 1 deletion framework/db/mysql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected function loadColumnSchema($info)
if (isset($values[1])) {
$column->scale = (int) $values[1];
}
if ($column->size === 1 && $type === 'bit') {
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
$column->type = 'boolean';
} elseif ($type === 'bit') {
if ($column->size > 32) {
Expand Down
59 changes: 59 additions & 0 deletions framework/helpers/BaseStringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,63 @@ public static function mb_ucwords($string, $encoding = 'UTF-8')

return implode('', $parts);
}

/**
* Masks a portion of a string with a repeated character.
* This method is multibyte-safe.
*
* @param string $string The input string.
* @param int $start The starting position from where to begin masking.
* This can be a positive or negative integer.
* Positive values count from the beginning,
* negative values count from the end of the string.
* @param int $length The length of the section to be masked.
* The masking will start from the $start position
* and continue for $length characters.
* @param string $mask The character to use for masking. The default is '*'.
* @return string The masked string.
*/
public static function mask($string, $start, $length, $mask = '*') {
$strLength = mb_strlen($string, 'UTF-8');

// Return original string if start position is out of bounds
if ($start >= $strLength || $start < -$strLength) {
return $string;
}

$masked = mb_substr($string, 0, $start, 'UTF-8');
$masked .= str_repeat($mask, abs($length));
$masked .= mb_substr($string, $start + abs($length), null, 'UTF-8');

return $masked;
}

/**
* Returns the portion of the string that lies between the first occurrence of the start string
* and the last occurrence of the end string after that.
*
* @param string $string The input string.
* @param string $start The string marking the start of the portion to extract.
* @param string $end The string marking the end of the portion to extract.
* @return string|null The portion of the string between the first occurrence of
* start and the last occurrence of end, or null if either start or end cannot be found.
*/
public static function findBetween($string, $start, $end)
{
$startPos = mb_strpos($string, $start);

if ($startPos === false) {
return null;
}

// Cut the string from the start position
$subString = mb_substr($string, $startPos + mb_strlen($start));
$endPos = mb_strrpos($subString, $end);

if ($endPos === false) {
return null;
}

return mb_substr($subString, 0, $endPos);
}
}
8 changes: 4 additions & 4 deletions framework/messages/fa/yii.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'"{attribute}" does not support operator "{operator}".' => '"{attribute}" از عملگر "{operator}" پشتیبانی نمی‌کند.',
'(not set)' => '(تنظیم نشده)',
'Action not found.' => 'عمل یافت نشد.',
'Aliases available: {aliases}' => 'نام مستعارهای موجود: {aliases}',
'Aliases available: {aliases}' => 'نام‌های مستعار موجود: {aliases}',
'An internal server error occurred.' => 'خطای داخلی سرور رخ داده است.',
'Are you sure you want to delete this item?' => 'آیا اطمینان به حذف این مورد دارید؟',
'Condition for "{attribute}" should be either a value or valid operator specification.' => 'شرط برای "{attribute}" باید یک مقدار یا مشخصه‌ی عملگر معتبر باشد.',
Expand All @@ -49,11 +49,11 @@
'Page not found.' => 'صفحه‌ای یافت نشد.',
'Please fix the following errors:' => 'لطفاً خطاهای زیر را رفع نمائید:',
'Please upload a file.' => 'لطفاً یک فایل آپلود کنید.',
'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.' => 'نمایش <b>{begin, number} تا {end, number}</b> مورد از کل <b>{totalCount, number}</b> مورد.',
'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.' => 'نمایش <b>{begin, number}</b> تا <b>{end, number}</b> مورد از کل <b>{totalCount, number}</b> مورد.',
'The combination {values} of {attributes} has already been taken.' => 'مقدار {values} از {attributes} قبلاً گرفته شده است.',
'The file "{file}" is not an image.' => 'فایل "{file}" یک تصویر نیست.',
'The file "{file}" is too big. Its size cannot exceed {formattedLimit}.' => 'حجم فایل "{file}" بسیار بیشتر می‌باشد. حجم آن نمی‌تواند از {formattedLimit} بیشتر باشد.',
'The file "{file}" is too small. Its size cannot be smaller than {formattedLimit}.' => 'حجم فایل "{file}" بسیار کم می‌باشد. حجم آن‌نمی تواند از {formattedLimit} کمتر باشد.',
'The file "{file}" is too small. Its size cannot be smaller than {formattedLimit}.' => 'حجم فایل "{file}" بسیار کم می‌باشد. حجم آن نمی‌تواند از {formattedLimit} کمتر باشد.',
'The format of {attribute} is invalid.' => 'قالب {attribute} نامعتبر است.',
'The format of {filter} is invalid.' => 'قالب {filter} نامعتبر است.',
'The image "{file}" is too large. The height cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => 'تصویر "{file}" خیلی بزرگ است. ارتفاع نمی‌تواند بزرگتر از {limit, number} پیکسل باشد.',
Expand Down Expand Up @@ -87,7 +87,7 @@
'{attribute} is invalid.' => '{attribute} معتبر نیست.',
'{attribute} is not a valid URL.' => '{attribute} یک URL معتبر نیست.',
'{attribute} is not a valid email address.' => '{attribute} یک آدرس ایمیل معتبر نیست.',
'{attribute} is not in the allowed range.' => '{attribute} در محدوده مجاز نمیباشد.',
'{attribute} is not in the allowed range.' => '{attribute} در محدوده مجاز نمیباشد.',
'{attribute} must be "{requiredValue}".' => '{attribute} باید "{requiredValue}" باشد.',
'{attribute} must be a number.' => '{attribute} باید یک عدد باشد.',
'{attribute} must be a string.' => '{attribute} باید یک رشته باشد.',
Expand Down
41 changes: 39 additions & 2 deletions tests/framework/caching/DbDependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class DbDependencyTest extends DatabaseTestCase
*/
protected $driverName = 'sqlite';


/**
* {@inheritdoc}
*/
Expand All @@ -39,11 +38,14 @@ protected function setUp(): void
$db->createCommand()->insert('dependency_item', ['value' => 'initial'])->execute();
}

public function testIsChanged(): void
public function testQueryOneIsExecutedWhenQueryCacheEnabled()
{
$db = $this->getConnection(false);
$cache = new ArrayCache();

// Enable the query cache
$db->enableQueryCache = true;

$dependency = new DbDependency();
$dependency->db = $db;
$dependency->sql = 'SELECT [[id]] FROM {{dependency_item}} ORDER BY [[id]] DESC LIMIT 1';
Expand All @@ -56,4 +58,39 @@ public function testIsChanged(): void

$this->assertTrue($dependency->isChanged($cache));
}

public function testQueryOneIsExecutedWhenQueryCacheDisabled()
{
$db = $this->getConnection(false);
$cache = new ArrayCache();

// Disable the query cache
$db->enableQueryCache = false;

$dependency = new DbDependency();
$dependency->db = $db;
$dependency->sql = 'SELECT [[id]] FROM {{dependency_item}} ORDER BY [[id]] DESC LIMIT 1';
$dependency->reusable = false;

$dependency->evaluateDependency($cache);
$this->assertFalse($dependency->isChanged($cache));

$db->createCommand()->insert('dependency_item', ['value' => 'new'])->execute();

$this->assertTrue($dependency->isChanged($cache));
}

public function testMissingSqlThrowsException()
{
$this->expectException('\yii\base\InvalidConfigException');

$db = $this->getConnection(false);
$cache = new ArrayCache();

$dependency = new DbDependency();
$dependency->db = $db;
$dependency->sql = null;

$dependency->evaluateDependency($cache);
}
}
6 changes: 5 additions & 1 deletion tests/framework/db/mysql/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,13 @@ public function getExpectedColumns()
]
);

$columns['bool_col']['type'] = 'boolean';
$columns['bool_col']['phpType'] = 'boolean';
$columns['bool_col2']['type'] = 'boolean';
$columns['bool_col2']['phpType'] = 'boolean';

if (version_compare($version, '5.7', '<')) {
$columns['int_col3']['phpType'] = 'string';

$columns['json_col']['type'] = 'text';
$columns['json_col']['dbType'] = 'longtext';
$columns['json_col']['phpType'] = 'string';
Expand Down
Loading

0 comments on commit 0294cf4

Please sign in to comment.