Skip to content

Commit

Permalink
多言語対応
Browse files Browse the repository at this point in the history
  • Loading branch information
s-nakajima committed Jan 5, 2017
1 parent a2a786e commit 487c6e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
32 changes: 10 additions & 22 deletions Utility/InstallUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,31 +749,17 @@ private function __commandOutputResults($type, $messages) {
*/
public function saveSiteSetting($data = array()) {
$this->Language = ClassRegistry::init('M17n.Language');
$this->SiteSetting = ClassRegistry::init('SiteManager.SiteSetting');

if (! $this->validatesSiteSetting($data)) {
return false;
}
$this->SiteSetting = ClassRegistry::init('SitManager.SiteSetting');

try {
$update = array(
'is_active' => true,
);
$conditions = array(
'code' => $data['Language']['code']
);
if (! $this->Language->updateAll($update, $conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
$this->Language->begin();

if (! $this->validatesSiteSetting($data)) {
return false;
}

$update = array(
'is_active' => false,
);
$conditions = array(
'code NOT IN' => $data['Language']['code']
);
if (! $this->Language->updateAll($update, $conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
if (! $this->Language->saveActive($data)) {
return false;
}

if (! in_array(Configure::read('Config.language'), $data['Language']['code'], true)) {
Expand All @@ -787,14 +773,16 @@ public function saveSiteSetting($data = array()) {
if (! $this->SiteSetting->updateAll($update, $conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
}

if (! in_array(Configure::read('Config.language'), $data['Language']['code'], true)) {
$this->saveAppConf();
}

$this->Language->commit();

} catch (Exception $ex) {
$this->Language->rollback($ex);
throw $ex;
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions Utility/InstallValidatorUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ private function __displayVersionMessage($message) {
* @return bool
*/
public function validatesSiteSetting($data) {
$this->Language = ClassRegistry::init('M17n.Language');
$this->_fields = array();

$fieldName = 'Language.code';
if (! isset($data['Language']['code']) || count($data['Language']['code']) === 0) {
$this->invalidate($fieldName, __d('install', 'Please select the language to use.'));
if (! $this->Language->validateActive($data)) {
$this->validationErrors = $this->Language->validationErrors;
}

return count($this->validationErrors) === 0;
Expand Down

0 comments on commit 487c6e8

Please sign in to comment.