Commit 10cc19d0 by Qiang Xue

Fixes #5833: The `message` command fails with a FK constraint error when trying to update messages

parent 2910322b
...@@ -15,6 +15,7 @@ Yii Framework 2 Change Log ...@@ -15,6 +15,7 @@ Yii Framework 2 Change Log
- Bug #5702: Parenthesis should be automatically added to `Validator::whenClient` to avoid js error (mdmunir, qiangxue) - Bug #5702: Parenthesis should be automatically added to `Validator::whenClient` to avoid js error (mdmunir, qiangxue)
- Bug #5745: Gii and debug modules may cause 404 exception when the route contains dashes (qiangxue) - Bug #5745: Gii and debug modules may cause 404 exception when the route contains dashes (qiangxue)
- Bug #5780: `QueryBuilder::batchInsert()` may cause "undefined index" error (qiangxue) - Bug #5780: `QueryBuilder::batchInsert()` may cause "undefined index" error (qiangxue)
- Bug #5833: The `message` command fails with a FK constraint error when trying to update messages (qiangxue)
- Bug: Gii console command help information does not contain global options (qiangxue) - Bug: Gii console command help information does not contain global options (qiangxue)
- Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark) - Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark)
- Enh #5223: Query builder now supports selecting sub-queries as columns (qiangxue) - Enh #5223: Query builder now supports selecting sub-queries as columns (qiangxue)
......
...@@ -203,10 +203,10 @@ class MessageController extends Controller ...@@ -203,10 +203,10 @@ class MessageController extends Controller
$db->createCommand() $db->createCommand()
->insert($sourceMessageTable, ['category' => $category, 'message' => $m])->execute(); ->insert($sourceMessageTable, ['category' => $category, 'message' => $m])->execute();
$lastId = $db->getLastInsertID(); $lastID = $db->getLastInsertID();
foreach ($languages as $language) { foreach ($languages as $language) {
$db->createCommand() $db->createCommand()
->insert($messageTable, ['id' => $lastId, 'language' => $language])->execute(); ->insert($messageTable, ['id' => $lastID, 'language' => $language])->execute();
} }
} }
} }
...@@ -222,17 +222,12 @@ class MessageController extends Controller ...@@ -222,17 +222,12 @@ class MessageController extends Controller
->delete($sourceMessageTable, ['in', 'id', $obsolete])->execute(); ->delete($sourceMessageTable, ['in', 'id', $obsolete])->execute();
echo "deleted.\n"; echo "deleted.\n";
} else { } else {
$last_id = $db->getLastInsertID();
$db->createCommand() $db->createCommand()
->update( ->update(
$sourceMessageTable, $sourceMessageTable,
['message' => new \yii\db\Expression("CONCAT('@@',message,'@@')")], ['message' => new \yii\db\Expression("CONCAT('@@',message,'@@')")],
['in', 'id', $obsolete] ['in', 'id', $obsolete]
)->execute(); )->execute();
foreach ($languages as $language) {
$db->createCommand()
->insert($messageTable, ['id' => $last_id, 'language' => $language])->execute();
}
echo "updated.\n"; echo "updated.\n";
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment