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
4fe0eeb1
Commit
4fe0eeb1
authored
Jan 21, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refacotring.
parent
92215a2f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
26 deletions
+21
-26
MessageController.php
framework/console/controllers/MessageController.php
+18
-24
messageConfig.php
framework/views/messageConfig.php
+3
-2
No files found.
framework/console/controllers/MessageController.php
View file @
4fe0eeb1
...
@@ -129,20 +129,14 @@ class MessageController extends Controller
...
@@ -129,20 +129,14 @@ class MessageController extends Controller
}
}
}
}
}
elseif
(
$config
[
'format'
]
===
'db'
)
{
}
elseif
(
$config
[
'format'
]
===
'db'
)
{
$dbConnection
=
\Yii
::
$app
->
getComponent
(
isset
(
$config
[
'connectionID'
])
?
$config
[
'connectionID'
]
:
'db'
);
$db
=
\Yii
::
$app
->
getComponent
(
isset
(
$config
[
'db'
])
?
$config
[
'db'
]
:
'db'
);
if
(
!
$dbConnection
instanceof
\yii\db\Connection
)
{
if
(
!
$db
instanceof
\yii\db\Connection
)
{
throw
new
Exception
(
'The "connectionID" 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'
]
:
'SourceMessage'
;
$res
=
[];
foreach
(
$config
[
'languages'
]
as
$language
)
{
foreach
(
$messages
as
$category
=>
$msgs
)
{
$res
[
$category
]
=
$msgs
;
}
}
}
$sourceMessageTable
=
isset
(
$config
[
'sourceMessageTable'
])
?
$config
[
'sourceMessageTable'
]
:
'{{%source_message}}'
;
$this
->
saveMessagesToDb
(
$this
->
saveMessagesToDb
(
$
r
es
,
$
messag
es
,
$db
Connection
,
$db
,
$sourceMessageTable
,
$sourceMessageTable
,
$config
[
'removeUnused'
]
$config
[
'removeUnused'
]
);
);
...
@@ -153,11 +147,11 @@ class MessageController extends Controller
...
@@ -153,11 +147,11 @@ class MessageController extends Controller
* Saves messages to database
* Saves messages to database
*
*
* @param array $messages
* @param array $messages
* @param \yii\db\Connection $db
Connection
* @param \yii\db\Connection $db
* @param string $sourceMessageTable
* @param string $sourceMessageTable
* @param boolean $removeUnused
* @param boolean $removeUnused
*/
*/
protected
function
saveMessagesToDb
(
$messages
,
$db
Connection
,
$sourceMessageTable
,
$removeUnused
)
protected
function
saveMessagesToDb
(
$messages
,
$db
,
$sourceMessageTable
,
$removeUnused
)
{
{
$q
=
new
\yii\db\Query
;
$q
=
new
\yii\db\Query
;
$current
=
[];
$current
=
[];
...
@@ -200,7 +194,7 @@ class MessageController extends Controller
...
@@ -200,7 +194,7 @@ class MessageController extends Controller
foreach
(
$msgs
as
$m
)
{
foreach
(
$msgs
as
$m
)
{
$savedFlag
=
true
;
$savedFlag
=
true
;
$db
Connection
->
createCommand
()
$db
->
createCommand
()
->
insert
(
$sourceMessageTable
,
[
'category'
=>
$category
,
'message'
=>
$m
])
->
execute
();
->
insert
(
$sourceMessageTable
,
[
'category'
=>
$category
,
'message'
=>
$m
])
->
execute
();
}
}
}
}
...
@@ -212,11 +206,11 @@ class MessageController extends Controller
...
@@ -212,11 +206,11 @@ class MessageController extends Controller
echo
"nothing obsoleted...skipped.
\n
"
;
echo
"nothing obsoleted...skipped.
\n
"
;
}
else
{
}
else
{
if
(
$removeUnused
)
{
if
(
$removeUnused
)
{
$db
Connection
->
createCommand
()
$db
->
createCommand
()
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
])
->
execute
();
->
delete
(
$sourceMessageTable
,
[
'in'
,
'id'
,
$obsolete
])
->
execute
();
echo
"deleted.
\n
"
;
echo
"deleted.
\n
"
;
}
else
{
}
else
{
$db
Connection
->
createCommand
()
$db
->
createCommand
()
->
update
(
->
update
(
$sourceMessageTable
,
$sourceMessageTable
,
[
'message'
=>
new
\yii\db\Expression
(
"CONCAT('@@',message,'@@')"
)],
[
'message'
=>
new
\yii\db\Expression
(
"CONCAT('@@',message,'@@')"
)],
...
@@ -324,20 +318,20 @@ class MessageController extends Controller
...
@@ -324,20 +318,20 @@ class MessageController extends Controller
$fileName
.=
'.merged'
;
$fileName
.=
'.merged'
;
}
}
if
(
$format
===
'po'
){
if
(
$format
===
'po'
){
$out
_str
=
''
;
$out
put
=
''
;
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
)
===
'@@'
)
{
$out
_str
.=
"#msgid
\"
$k
\"\n
"
;
$out
put
.=
"#msgid
\"
$k
\"\n
"
;
$out
_str
.=
"#msgstr
\"
$v
\"\n
"
;
$out
put
.=
"#msgstr
\"
$v
\"\n
"
;
}
else
{
}
else
{
$out
_str
.=
"msgid
\"
$k
\"\n
"
;
$out
put
.=
"msgid
\"
$k
\"\n
"
;
$out
_str
.=
"msgstr
\"
$v
\"\n
"
;
$out
put
.=
"msgstr
\"
$v
\"\n
"
;
}
}
$out
_str
.=
"
\n
"
;
$out
put
.=
"
\n
"
;
}
}
$merged
=
$out
_str
;
$merged
=
$out
put
;
}
}
echo
"translation merged.
\n
"
;
echo
"translation merged.
\n
"
;
}
else
{
}
else
{
...
...
framework/views/messageConfig.php
View file @
4fe0eeb1
...
@@ -44,6 +44,7 @@ return [
...
@@ -44,6 +44,7 @@ return [
],
],
// Generated file format. Can be either "php", "po" or "db".
// Generated file format. Can be either "php", "po" or "db".
'format'
=>
'php'
,
'format'
=>
'php'
,
// Connection component ID for "db".
// When format is "db", you may specify the following two options
//'connectionID' => 'db',
//'db' => 'db',
//'sourceMessageTable' => '{{%source_message}}',
];
];
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