インストーラ改修(2) エラー検出とロールバック
app/config関連の権限設定を間違えていると、database.phpを作成する過程でエラーになります。
その付近のエラー検出追加と、ロールバック処理を追加しました。
app/config関連で必要な権限設定は以下の通り
app/config (777)
app/config/database.php.install (666)
app/config/その他 (ファイル644・ディレクトリ755)
app/configが書込み不可だと
rename(APP.'config'.DS.'database.php.install', APP.'config'.DS.'database.php');
がエラーになり、
app/config/database.php.installが書込み不可だと、database.phpも書込み不可になるので
$file->write($content)
がエラーになります。
app/config以下を全て777にしてしまう、でOKなのですが、不要に書込み可設定を行なうのは落ち着かないので・・・
renameエラーの検出
--- a/app/plugins/install/controllers/install_controller.php +++ b/app/plugins/install/controllers/install_controller.php @@ -67,26 +67,30 @@ class InstallController extends InstallAppController { if (mysql_connect($this->data['Install']['host'], $this->data['Install']['login'], $this-> mysql_select_db($this->data['Install']['database'])) { // rename database.php.install - rename(APP.'config'.DS.'database.php.install', APP.'config'.DS.'database.php'); + $result = @rename(APP.'config'.DS.'database.php.install', APP.'config'.DS.'database.ph + if ($result === false) { + $this->Session->setFlash(__('Could not make database.php file.', true)); + } else { (以下、追加した if 用のインデント差分のため略)
database.phpへの書込みが失敗した場合の処理。
renameしたdatabase.php.installの復帰を追加。
if($file->write($content) ) { $this->redirect(array('action' => 'data')); } else { $this->Session->setFlash(__('Could not write database.php file.', true)); + @rename(APP.'config'.DS.'database.php', APP.'config'.DS.'database.php.install'); }
最後に、app/configとapp/config/database.phpの権限を755/644に戻したいのですが、
chmodはサーバの環境などによりエラーになることもあるので、手動設定を促すメッセージを入れる事にしました
--- a/app/plugins/install/views/install/finish.ctp +++ b/app/plugins/install/views/install/finish.ctp @@ -2,9 +2,11 @@ <h2><?php echo $this->pageTitle; ?></h2> <p> + <?php __('Change the permission of <strong>app/config to 755</strong>, and <strong>app/config/database.php to 644</strong>.') ?> + </p> + + <p>