Skip to content

Commit

Permalink
Merge branch 'master' into update-all-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
NabiKAZ authored Oct 19, 2023
2 parents a441a3e + 5d8a96e commit 311d39b
Show file tree
Hide file tree
Showing 24 changed files with 328 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
run: sudo locale-gen fr_FR.UTF-8

- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP.
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create MS SQL Database
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

steps:
- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install dependencies.
run: composer update $DEFAULT_COMPOSER_FLAGS
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

steps:
- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

steps:
- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: Checkout.
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP with extensions.
uses: shivammathur/setup-php@v2
Expand Down
12 changes: 11 additions & 1 deletion build/controllers/MimeTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ private function generateMimeTypesFile($outFile, $content)
* Its content is generated from the apache http mime.types file.
* https://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup
* This file has been placed in the public domain for unlimited redistribution.
*
* All extra changes made to this file must be comitted to /build/controllers/MimeTypeController.php
* otherwise they will be lost on next build.
*/
\$mimeTypes = $array;
if (PHP_VERSION_ID >= 80100) {
# fix for bundled libmagic bug, see also https://github.com/yiisoft/yii2/issues/19925
if ((PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80122) || (PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80209)) {
\$mimeTypes = array_replace(\$mimeTypes, array('xz' => 'application/octet-stream'));
}
Expand All @@ -148,6 +152,9 @@ private function generateMimeAliasesFile($outFile)
* MIME aliases.
*
* This file contains aliases for MIME types.
*
* All extra changes made to this file must be comitted to /build/controllers/MimeTypeController.php
* otherwise they will be lost on next build.
*/
return $array;
Expand Down Expand Up @@ -209,6 +216,9 @@ private function generateMimeExtensionsFile($outFile, $content)
* Its content is generated from the apache http mime.types file.
* https://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup
* This file has been placed in the public domain for unlimited redistribution.
*
* All extra changes made to this file must be comitted to /build/controllers/MimeTypeController.php
* otherwise they will be lost on next build.
*/
return $array;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"ezyang/htmlpurifier": "^4.6",
"cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0",
"bower-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable",
"bower-asset/inputmask": "~3.2.2 | ~3.3.5 | ~5.0.8 ",
"bower-asset/punycode": "1.3.* | 2.2.*",
"bower-asset/inputmask": "^5.0.8 ",
"bower-asset/punycode": "^2.2",
"bower-asset/yii2-pjax": "~2.0.1",
"paragonie/random_compat": ">=1"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/guide-ru/structure-controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class HelloWorldAction extends Action
[[yii\console\Response::exitStatus|статус выхода]] исполнения команды.

В вышеприведенных примерах, все результаты действий являются строками, которые будут использованы в качестве тела ответа,
высланного пользователю. Следующий пример, показывает действие может перенаправить браузер пользователя на новый URL, с помощью
высланного пользователю. Следующий пример, показывает как действие может перенаправить браузер пользователя на новый URL, с помощью
возврата response объекта (т. к. [[yii\web\Controller::redirect()|redirect()]] метод возвращает response объект):

```php
Expand Down
8 changes: 8 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Yii Framework 2 Change Log
2.0.50 under development
------------------------

- 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)
- Enh #12743: Added new methods `BaseActiveRecord::loadRelations()` and `BaseActiveRecord::loadRelationsFor()` to eager load related models for existing primary model instances (PowerGamer1)


2.0.49.2 October 12, 2023
-------------------------

- Bug #19925: Improved PHP version check when handling MIME types (schmunk42)


Expand Down
8 changes: 8 additions & 0 deletions framework/assets/yii.activeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@
data: $form.serialize() + extData,
dataType: data.settings.ajaxDataType,
complete: function (jqXHR, textStatus) {
currentAjaxRequest = null;
$form.trigger(events.ajaxComplete, [jqXHR, textStatus]);
},
beforeSend: function (jqXHR, settings) {
currentAjaxRequest = jqXHR;
$form.trigger(events.ajaxBeforeSend, [jqXHR, settings]);
},
success: function (msgs) {
Expand Down Expand Up @@ -563,6 +565,9 @@
return;
}

if (currentAjaxRequest !== null) {
currentAjaxRequest.abort();
}
if (data.settings.timer !== undefined) {
clearTimeout(data.settings.timer);
}
Expand Down Expand Up @@ -929,4 +934,7 @@
$form.find(attribute.input).attr('aria-invalid', hasError ? 'true' : 'false');
}
}

var currentAjaxRequest = null;

})(window.jQuery);
4 changes: 2 additions & 2 deletions framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"ezyang/htmlpurifier": "^4.6",
"cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0",
"bower-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable",
"bower-asset/inputmask": "~3.2.2 | ~3.3.5 | ~5.0.8 ",
"bower-asset/punycode": "1.3.* | 2.2.*",
"bower-asset/inputmask": "^5.0.8 ",
"bower-asset/punycode": "^2.2",
"bower-asset/yii2-pjax": "~2.0.1",
"paragonie/random_compat": ">=1"
},
Expand Down
161 changes: 96 additions & 65 deletions framework/console/controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,7 @@ protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messag
foreach ($rows as $row) {
$currentMessages[$row['category']][$row['id']] = $row['message'];
}

$currentLanguages = [];
$rows = (new Query())->select(['language'])->from($messageTable)->groupBy('language')->all($db);
foreach ($rows as $row) {
$currentLanguages[] = $row['language'];
}
$missingLanguages = [];
if (!empty($currentLanguages)) {
$missingLanguages = array_diff($languages, $currentLanguages);
}


$new = [];
$obsolete = [];

Expand All @@ -372,89 +362,130 @@ protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messag

if (isset($currentMessages[$category])) {
$new[$category] = array_diff($msgs, $currentMessages[$category]);
// obsolete messages per category
$obsolete += array_diff($currentMessages[$category], $msgs);
} else {
$new[$category] = $msgs;
}
}


// obsolete categories
foreach (array_diff(array_keys($currentMessages), array_keys($messages)) as $category) {
$obsolete += $currentMessages[$category];
}

if (!$removeUnused) {
foreach ($obsolete as $pk => $msg) {
// skip already marked unused
if (strncmp($msg, '@@', 2) === 0 && substr($msg, -2) === '@@') {
unset($obsolete[$pk]);
}
}
}

$obsolete = array_keys($obsolete);
}

$this->stdout('Inserting new messages...');
$savedFlag = false;
$insertCount = 0;

foreach ($new as $category => $msgs) {
foreach ($msgs as $msg) {
$savedFlag = true;
$lastPk = $db->schema->insert($sourceMessageTable, ['category' => $category, 'message' => $msg]);
foreach ($languages as $language) {
$db->createCommand()
->insert($messageTable, ['id' => $lastPk['id'], 'language' => $language])
->execute();
}
}
}

if (!empty($missingLanguages)) {
$updatedMessages = [];
$rows = (new Query())->select(['id', 'category', 'message'])->from($sourceMessageTable)->all($db);
foreach ($rows as $row) {
$updatedMessages[$row['category']][$row['id']] = $row['message'];
}
foreach ($updatedMessages as $category => $msgs) {
foreach ($msgs as $id => $msg) {
$savedFlag = true;
foreach ($missingLanguages as $language) {
$db->createCommand()
->insert($messageTable, ['id' => $id, 'language' => $language])
->execute();
}
}
$insertCount++;
$db->schema->insert($sourceMessageTable, ['category' => $category, 'message' => $msg]);
}
}

$this->stdout($savedFlag ? "saved.\n" : "Nothing to save.\n");

$this->stdout($insertCount ? "{$insertCount} saved.\n" : "Nothing to save.\n");

$this->stdout($removeUnused ? 'Deleting obsoleted messages...' : 'Updating obsoleted messages...');

if (empty($obsolete)) {
$this->stdout("Nothing obsoleted...skipped.\n");
return;
}

if ($removeUnused) {
$db->createCommand()
->delete($sourceMessageTable, ['in', 'id', $obsolete])
->execute();
$this->stdout("deleted.\n");
} elseif ($markUnused) {
$rows = (new Query())
->select(['id', 'message'])
->from($sourceMessageTable)
->where(['in', 'id', $obsolete])
->all($db);

foreach ($rows as $row) {
$db->createCommand()->update(
$sourceMessageTable,
['message' => '@@' . $row['message'] . '@@'],
['id' => $row['id']]
)->execute();
if ($obsolete) {
if ($removeUnused) {
$affected = $db->createCommand()
->delete($sourceMessageTable, ['in', 'id', array_keys($obsolete)])
->execute();
$this->stdout("{$affected} deleted.\n");
} elseif ($markUnused) {
$marked=0;
$rows = (new Query())
->select(['id', 'message'])
->from($sourceMessageTable)
->where(['in', 'id', array_keys($obsolete)])
->all($db);

foreach ($rows as $row) {
$marked++;
$db->createCommand()->update(
$sourceMessageTable,
['message' => '@@' . $row['message'] . '@@'],
['id' => $row['id']]
)->execute();
}
$this->stdout("{$marked} updated.\n");
} else {
$this->stdout("kept untouched.\n");
}
$this->stdout("updated.\n");
} else {
$this->stdout("kept untouched.\n");
}

// get fresh message id list
$freshMessagesIds = [];
$rows = (new Query())->select(['id'])->from($sourceMessageTable)->all($db);
foreach ($rows as $row) {
$freshMessagesIds[] = $row['id'];
}

$this->stdout("Generating missing rows...");
$generatedMissingRows = [];

foreach ($languages as $language) {
$count = 0;

// get list of ids of translations for this language
$msgRowsIds = [];
$msgRows = (new Query())->select(['id'])->from($messageTable)->where([
'language'=>$language,
])->all($db);
foreach ($msgRows as $row) {
$msgRowsIds[] = $row['id'];
}

// insert missing
foreach ($freshMessagesIds as $id) {
if (!in_array($id, $msgRowsIds)) {
$db->createCommand()
->insert($messageTable, ['id' => $id, 'language' => $language])
->execute();
$count++;
}
}
if ($count) {
$generatedMissingRows[] = "{$count} for {$language}";
}
}

$this->stdout($generatedMissingRows ? implode(", ", $generatedMissingRows).".\n" : "Nothing to do.\n");

$this->stdout("Dropping unused languages...");
$droppedLanguages=[];

$currentLanguages = [];
$rows = (new Query())->select(['language'])->from($messageTable)->groupBy('language')->all($db);
foreach ($rows as $row) {
$currentLanguages[] = $row['language'];
}

foreach ($currentLanguages as $currentLanguage) {
if (!in_array($currentLanguage, $languages)) {
$deleted=$db->createCommand()->delete($messageTable, "language=:language", [
'language'=>$currentLanguage,
])->execute();
$droppedLanguages[] = "removed {$deleted} rows for $currentLanguage";
}
}

$this->stdout($droppedLanguages ? implode(", ", $droppedLanguages).".\n" : "Nothing to do.\n");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/console/controllers/ServeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function actionIndex($address = 'localhost')
}
$this->stdout("Quit the server with CTRL-C or COMMAND-C.\n");

passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" $router");
passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" \"$router\"");
}

/**
Expand Down
Loading

0 comments on commit 311d39b

Please sign in to comment.