Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
1a14ed21
Commit
1a14ed21
authored
Mar 04, 2014
by
Sorokin Victor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update MessageController.php
parent
4d4a3f08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
MessageController.php
framework/console/controllers/MessageController.php
+21
-21
No files found.
framework/console/controllers/MessageController.php
View file @
1a14ed21
...
@@ -134,14 +134,14 @@ class MessageController extends Controller
...
@@ -134,14 +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}}'
;
$messageTable
=
isset
(
$config
[
'messageTable'
])
?
$config
[
'messageTable'
]
:
'{{%message}}'
;
$this
->
saveMessagesToDb
(
$this
->
saveMessagesToDb
(
$messages
,
$messages
,
$db
,
$db
,
$sourceMessageTable
,
$sourceMessageTable
,
$messageTable
,
$messageTable
,
$config
[
'removeUnused'
],
$config
[
'removeUnused'
],
$config
[
'languages'
]
$config
[
'languages'
]
);
);
}
}
}
}
...
@@ -152,9 +152,9 @@ class MessageController extends Controller
...
@@ -152,9 +152,9 @@ 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 string $messageTable
* @param boolean $removeUnused
* @param boolean $removeUnused
* @param array $languages
* @param array $languages
*/
*/
protected
function
saveMessagesToDb
(
$messages
,
$db
,
$sourceMessageTable
,
$messageTable
,
$removeUnused
,
$languages
)
protected
function
saveMessagesToDb
(
$messages
,
$db
,
$sourceMessageTable
,
$messageTable
,
$removeUnused
,
$languages
)
{
{
...
@@ -195,16 +195,16 @@ class MessageController extends Controller
...
@@ -195,16 +195,16 @@ class MessageController extends Controller
echo
"Inserting new messages..."
;
echo
"Inserting new messages..."
;
$savedFlag
=
false
;
$savedFlag
=
false
;
foreach
(
$new
as
$category
=>
$msgs
)
{
foreach
(
$new
as
$category
=>
$msgs
)
{
foreach
(
$msgs
as
$m
)
{
foreach
(
$msgs
as
$m
)
{
$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
();
$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
();
}
}
}
}
}
}
...
@@ -217,19 +217,19 @@ class MessageController extends Controller
...
@@ -217,19 +217,19 @@ 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
();
$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
)
{
foreach
(
$languages
as
$language
)
{
$db
->
createCommand
()
$db
->
createCommand
()
->
insert
(
$messageTable
,
[
'id'
=>
$last_id
,
'language'
=>
$language
])
->
execute
();
->
insert
(
$messageTable
,
[
'id'
=>
$last_id
,
'language'
=>
$language
])
->
execute
();
}
}
echo
"updated.
\n
"
;
echo
"updated.
\n
"
;
}
}
...
@@ -283,7 +283,7 @@ class MessageController extends Controller
...
@@ -283,7 +283,7 @@ class MessageController extends Controller
{
{
echo
"Saving messages to
$fileName
..."
;
echo
"Saving messages to
$fileName
..."
;
if
(
is_file
(
$fileName
))
{
if
(
is_file
(
$fileName
))
{
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$translated
=
file_get_contents
(
$fileName
);
$translated
=
file_get_contents
(
$fileName
);
preg_match_all
(
'/(?<=msgid ").*(?="\n(#*)msgstr)/'
,
$translated
,
$keys
);
preg_match_all
(
'/(?<=msgid ").*(?="\n(#*)msgstr)/'
,
$translated
,
$keys
);
preg_match_all
(
'/(?<=msgstr ").*(?="\n\n)/'
,
$translated
,
$values
);
preg_match_all
(
'/(?<=msgstr ").*(?="\n\n)/'
,
$translated
,
$values
);
...
@@ -300,7 +300,7 @@ class MessageController extends Controller
...
@@ -300,7 +300,7 @@ class MessageController extends Controller
$merged
=
[];
$merged
=
[];
$untranslated
=
[];
$untranslated
=
[];
foreach
(
$messages
as
$message
)
{
foreach
(
$messages
as
$message
)
{
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$message
=
preg_replace
(
'/\"/'
,
'\"'
,
$message
);
$message
=
preg_replace
(
'/\"/'
,
'\"'
,
$message
);
}
}
if
(
array_key_exists
(
$message
,
$translated
)
&&
strlen
(
$translated
[
$message
])
>
0
)
{
if
(
array_key_exists
(
$message
,
$translated
)
&&
strlen
(
$translated
[
$message
])
>
0
)
{
...
@@ -332,9 +332,9 @@ class MessageController extends Controller
...
@@ -332,9 +332,9 @@ class MessageController extends Controller
if
(
false
===
$overwrite
)
{
if
(
false
===
$overwrite
)
{
$fileName
.=
'.merged'
;
$fileName
.=
'.merged'
;
}
}
if
(
$format
===
'po'
){
if
(
$format
===
'po'
)
{
$output
=
''
;
$output
=
''
;
foreach
(
$merged
as
$k
=>
$v
){
foreach
(
$merged
as
$k
=>
$v
)
{
$k
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$k
);
$k
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$k
);
$v
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$v
);
$v
=
preg_replace
(
'/(\")|(\\\")/'
,
"
\\\"
"
,
$v
);
if
(
substr
(
$v
,
0
,
2
)
===
'@@'
&&
substr
(
$v
,
-
2
)
===
'@@'
)
{
if
(
substr
(
$v
,
0
,
2
)
===
'@@'
&&
substr
(
$v
,
-
2
)
===
'@@'
)
{
...
@@ -353,7 +353,7 @@ class MessageController extends Controller
...
@@ -353,7 +353,7 @@ class MessageController extends Controller
if
(
$format
===
'po'
)
{
if
(
$format
===
'po'
)
{
$merged
=
''
;
$merged
=
''
;
sort
(
$messages
);
sort
(
$messages
);
foreach
(
$messages
as
$message
)
{
foreach
(
$messages
as
$message
)
{
$message
=
preg_replace
(
'/(\")|(\\\")/'
,
'\\\"'
,
$message
);
$message
=
preg_replace
(
'/(\")|(\\\")/'
,
'\\\"'
,
$message
);
$merged
.=
"msgid
\"
$message
\"\n
"
;
$merged
.=
"msgid
\"
$message
\"\n
"
;
$merged
.=
"msgstr
\"\"\n
"
;
$merged
.=
"msgstr
\"\"\n
"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment