<?php
/**
* DB設定更新タスク
*
* PHP version 5
*
* @author     stk2k <stk2k@sazysoft.com>
* @copyright  2008 stk2k, sazysoft
*/
class DBConfigUpdateTask extends SimpleTask implements ITask
{
	public $success;

	/*
	 *    コンストラクタ
	 */
	public function __construct()
	{
		$this->success = FALSE;

		parent::__construct();
	}

	/**
	 * イベントを処理する
	 */
	public function processEvent( IEvent $event, TaskSnapshot $snapshot )
	{

		// フォームデータを取得
		$backend    = $event->get( s('backend') );
		$server     = $event->get( s('server') );
		$user       = $event->get( s('user') );
		$password   = $event->get( s('password') );
		$db_name    = $event->get( s('db_name') );
		$charset    = $event->get( s('charset') );

		// テキストデータを作成
		$text  = "";
		$text .= "backend   = $backend" . PHP_EOL;
		$text .= "server    = $server" . PHP_EOL;
		$text .= "user      = $user" . PHP_EOL;
		$text .= "password  = $password" . PHP_EOL;
		$text .= "db_name   = $db_name" . PHP_EOL;
		$text .= "charset   = $charset" . PHP_EOL;

		// 出力先
		$profile_name = Profile::getProfileName();
		$config_file = WEBAPP_DIR . "/" . APPLICATION . "/config/data_sources/pear_db.$profile_name.data_source.ini";

		// ファイル出力
		$fp = fopen($config_file,"w");
		fwrite($fp, $text);
		fclose($fp);

		$this->success = TRUE;

		return b(TRUE);
	}

}
