Commit 51d6db7d by Alexander Makarov

Merge pull request #2607 from mitalcoi/db_message_source

enchansment of db message source
parents ef12934b 1a14ed21
...@@ -134,11 +134,14 @@ class MessageController extends Controller ...@@ -134,11 +134,14 @@ class MessageController extends Controller
throw new Exception('The "db" option must refer to a valid database application component.'); throw new Exception('The "db" option must refer to a valid database application component.');
} }
$sourceMessageTable = isset($config['sourceMessageTable']) ? $config['sourceMessageTable'] : '{{%source_message}}'; $sourceMessageTable = isset($config['sourceMessageTable']) ? $config['sourceMessageTable'] : '{{%source_message}}';
$messageTable = isset($config['messageTable']) ? $config['messageTable'] : '{{%message}}';
$this->saveMessagesToDb( $this->saveMessagesToDb(
$messages, $messages,
$db, $db,
$sourceMessageTable, $sourceMessageTable,
$config['removeUnused'] $messageTable,
$config['removeUnused'],
$config['languages']
); );
} }
} }
...@@ -149,9 +152,11 @@ class MessageController extends Controller ...@@ -149,9 +152,11 @@ class MessageController extends Controller
* @param array $messages * @param array $messages
* @param \yii\db\Connection $db * @param \yii\db\Connection $db
* @param string $sourceMessageTable * @param string $sourceMessageTable
* @param string $messageTable
* @param boolean $removeUnused * @param boolean $removeUnused
* @param array $languages
*/ */
protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $removeUnused) protected function saveMessagesToDb($messages, $db, $sourceMessageTable, $messageTable, $removeUnused, $languages)
{ {
$q = new \yii\db\Query; $q = new \yii\db\Query;
$current = []; $current = [];
...@@ -195,7 +200,12 @@ class MessageController extends Controller ...@@ -195,7 +200,12 @@ class MessageController extends Controller
$savedFlag = true; $savedFlag = true;
$db->createCommand() $db->createCommand()
->insert($sourceMessageTable, ['category' => $category, 'message' => $m])->execute(); ->insert($sourceMessageTable, ['category' => $category, 'message' => $m])->execute();
$lastId = $db->getLastInsertID();
foreach ($languages as $language) {
$db->createCommand()
->insert($messageTable, ['id' => $lastId, 'language' => $language])->execute();
}
} }
} }
...@@ -207,15 +217,20 @@ class MessageController extends Controller ...@@ -207,15 +217,20 @@ class MessageController extends Controller
} else { } else {
if ($removeUnused) { if ($removeUnused) {
$db->createCommand() $db->createCommand()
->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