2011-09-10 5 views
0

私はCodeigniterを使用して独自のCMSを構築しようとしています。 私は既にいくつかのモジュールを書きました。しかし、時間がたつにつれて、私はそれらといくつかの変更を加えました。 今、モジュールをアップグレードしたいのですが。私はftpでファイルを送信し、phpmyadminでデータベースフィールドを変更します。データベースプロセスのCodeigniterアップグレード可能なモジュールロジック

私はこのモジュールを使用しているすべてのプロジェクトで、変更が必要なものを誤ってしまう可能性があります。これらの変更をもう一度繰り返す必要があります。

今、私はインストールシステムを作るつもりです。

私のモジュールのディレクトリ構造は以下のように:

/modules 
/modules/survey/ 
/modules/survey/config 
/modules/survey/config/autoload.php 
/modules/survey/config/config.php 
/modules/survey/config/routes.php 
/modules/survey/config/install.php 
/modules/survey/controllers 
/modules/survey/controllers/entry.php... 
/modules/survey/models 
/modules/survey/models/survey.php... 
/modules/survey/views 
/modules/survey/views/index.php... 

私はすべてのモジュールは、configディレクトリにinstall.phpをファイルを持っているべきであると考えました。それはreleatedモジュールの設定を維持しています。以下のように:私は、インストールスクリプトを作成しようとしています、今

id, module, module_slug, version 

$config['version'] = 1.1; //or 1.2, 1.3 etc. 
$config['module'] = 'Survey Module'; 
$config['module_slug'] = 'survey'; 
$config['module_db_table'] = 'module_survey'; 

私はすでにinstalled_modulesテーブルを持っています。以下のように:

私はモジュールのファイルをzipします。

1- upload zip file with an installation page to a temp directory 
2- unzip the module in this temp direcorty 
3- Find install.php 
4- Get modules information from install.php 
5- Check if this module already in installed_modules table. 
6a) If it's not: I will make a new module_survey table. And copy this temp directory into the real modules directory. 
6b) If it's already : I have to change the structure of this table without lossing the data added before. Delete all module files and copy the new ones from temp into the modules directory. 
7- When everything done, Delete temp directory. 

私は6aと6bを貼り付けました。

6aの場合、e.x 'module_survey'テーブルはどのように作成するのですか。 iは

$config['db_query'] = "CREATE TABLE IF NOT EXISTS `module_survey` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`name` varchar(50) DEFAULT NULL, 
`lang_id` int(11) NOT NULL DEFAULT '1', 
`usort` int(3) DEFAULT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; 
"; 

ようinstall.phpの中で$の設定[ 'db_query']を追加して、このクエリを実行する必要があります。あなたのアドバイスは何ですか? 1つのテーブルだけではなく、2つ以上のモジュールが互いに関係している必要があります。

及び6bの場合:

私は私が名前の「temp_module_survey」のような新しい一時テーブルを作成する必要があり、思いました。

古いフィールド=
$ oldFields = $ this-> db-> field_data( 'module_survey');

(新しいフィールド用)= $ newFields = $ this-> db-> field_data( 'temp_module_survey');

は、新たに追加され、削除され、fieldDataが変更されたフィールドを比較します。 および oldfieldに新しいフィールドを追加 oldTable から不要なフィールドを削除し、fieldDataが変更されたフィールドを更新します。

次に、一時テーブルを削除します。

要約すると、古いデータを失うことなくデータベースを変更するにはどうすればよいですか。

私は説明できることを願っています。

ありがとうございます。

答えて

関連する問題