2007-10-17 14:43:34 +04:00
< ? php
/*
2009-06-04 02:44:32 +04:00
* This file is part of Mibew Messenger project .
2009-08-04 20:30:39 +04:00
*
2009-06-04 02:44:32 +04:00
* Copyright ( c ) 2005 - 2009 Mibew Messenger Community
2009-08-04 19:03:27 +04:00
* All rights reserved . The contents of this file are subject to the terms of
* the Eclipse Public License v1 . 0 which accompanies this distribution , and
* is available at http :// www . eclipse . org / legal / epl - v10 . html
2009-08-04 20:30:39 +04:00
*
2009-08-04 17:38:37 +04:00
* Alternatively , the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later ( the " GPL " ), in which case
* the provisions of the GPL are applicable instead of those above . If you wish
* to allow use of your version of this file only under the terms of the GPL , and
* not to allow others to use your version of this file under the terms of the
* EPL , indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL .
2009-08-04 20:30:39 +04:00
*
2007-10-17 14:43:34 +04:00
* Contributors :
* Evgeny Gryaznov - initial API and implementation
*/
2008-06-05 01:36:54 +04:00
require_once ( '../libs/common.php' );
require_once ( '../libs/operator.php' );
require_once ( 'dbinfo.php' );
2007-10-17 14:43:34 +04:00
function runsql ( $query , $link ) {
2008-09-30 03:07:06 +04:00
$res = mysql_query ( $query , $link )
2007-10-17 14:43:34 +04:00
or show_install_err ( ' Query failed: ' . mysql_error ());
2008-09-30 03:07:06 +04:00
return $res ;
2007-10-17 14:43:34 +04:00
}
2009-05-31 19:29:55 +04:00
$act = verifyparam ( " act " , " /^(silentcreateall|createdb|ct|dt|addcolumns) $ / " );
2007-10-17 14:43:34 +04:00
$link = @ mysql_connect ( $mysqlhost , $mysqllogin , $mysqlpass )
or show_install_err ( 'Could not connect: ' . mysql_error ());
2008-09-30 03:07:06 +04:00
if ( $act == " silentcreateall " ) {
mysql_query ( " CREATE DATABASE $mysqldb " , $link )
or show_install_err ( ' Query failed: ' . mysql_error ());
foreach ( $dbtables as $id ) {
create_table ( $id , $link );
}
} else if ( $act == " createdb " ) {
mysql_query ( " CREATE DATABASE $mysqldb " , $link )
2007-10-17 14:43:34 +04:00
or show_install_err ( ' Query failed: ' . mysql_error ());
} else {
2008-09-30 03:07:06 +04:00
mysql_select_db ( $mysqldb , $link )
2007-10-17 14:43:34 +04:00
or show_install_err ( 'Could not select database' );
if ( $force_charset_in_connection ) {
mysql_query ( " SET character set $dbencoding " , $link );
}
2008-09-30 03:07:06 +04:00
2009-05-31 19:29:55 +04:00
if ( $act == " ct " ) {
2007-10-17 14:43:34 +04:00
$curr_tables = get_tables ( $link );
if ( $curr_tables === false ) {
show_install_err ( $errors [ 0 ]);
}
$tocreate = array_diff ( array_keys ( $dbtables ), $curr_tables );
foreach ( $tocreate as $id ) {
create_table ( $id , $link );
}
2009-05-31 19:29:55 +04:00
} else if ( $act == " dt " ) {
2007-10-17 14:43:34 +04:00
foreach ( array_keys ( $dbtables ) as $id ) {
mysql_query ( " DROP TABLE IF EXISTS $id " , $link )
or show_install_err ( ' Query failed: ' . mysql_error ());
2008-09-30 03:07:06 +04:00
}
2007-10-17 14:43:34 +04:00
} else if ( $act == " addcolumns " ) {
$absent = array ();
foreach ( $dbtables as $id => $columns ) {
$curr_columns = get_columns ( $id , $link );
if ( $curr_columns === false ) {
2008-09-30 03:07:06 +04:00
show_install_err ( $errors [ 0 ]);
2007-10-17 14:43:34 +04:00
}
$tocreate = array_diff ( array_keys ( $columns ), $curr_columns );
foreach ( $tocreate as $v ) {
$absent [] = " $id . $v " ;
}
}
2008-09-30 03:07:06 +04:00
2007-10-17 14:43:34 +04:00
if ( in_array ( " chatmessage.agentId " , $absent ) ) {
runsql ( " ALTER TABLE chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind " , $link );
2008-09-30 03:07:06 +04:00
runsql ( " update chatmessage,chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname) " , $link );
2007-10-17 14:43:34 +04:00
}
2008-09-30 03:07:06 +04:00
2007-10-17 14:43:34 +04:00
if ( in_array ( " chatthread.agentId " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName " , $link );
2008-09-30 03:07:06 +04:00
runsql ( " update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName) " , $link );
2007-10-17 14:43:34 +04:00
}
2007-12-03 00:32:47 +03:00
2008-05-11 02:35:16 +04:00
if ( in_array ( " chatthread.agentTyping " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD agentTyping int DEFAULT 0 " , $link );
}
2008-09-30 03:07:06 +04:00
2008-05-11 02:35:16 +04:00
if ( in_array ( " chatthread.userTyping " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD userTyping int DEFAULT 0 " , $link );
}
2008-06-05 02:51:46 +04:00
if ( in_array ( " chatthread.messageCount " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD messageCount varchar(16) " , $link );
2008-09-30 03:07:06 +04:00
runsql ( " ALTER TABLE chatmessage ADD INDEX idx_threadid_ikind (threadid, ikind) " , $link );
runsql ( " UPDATE chatthread t SET t.messageCount = (SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1) " , $link );
2008-06-05 02:51:46 +04:00
runsql ( " ALTER TABLE chatmessage DROP INDEX idx_threadid_ikind " , $link );
}
2008-10-02 13:35:49 +04:00
if ( in_array ( " chatthread.nextagent " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD nextagent int NOT NULL DEFAULT 0 " , $link );
}
2008-10-03 19:11:02 +04:00
if ( in_array ( " chatthread.shownmessageid " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD shownmessageid int NOT NULL DEFAULT 0 " , $link );
}
if ( in_array ( " chatthread.userid " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD userid varchar(255) DEFAULT \" \" " , $link );
}
2008-12-08 03:34:28 +03:00
if ( in_array ( " chatoperator.iperm " , $absent ) ) {
runsql ( " ALTER TABLE chatoperator ADD iperm int DEFAULT 65535 " , $link );
}
2009-07-24 11:37:58 +04:00
if ( in_array ( " chatoperator.istatus " , $absent ) ) {
runsql ( " ALTER TABLE chatoperator ADD istatus int DEFAULT 0 " , $link );
}
2008-10-06 02:47:09 +04:00
if ( in_array ( " chatoperator.vcavatar " , $absent ) ) {
runsql ( " ALTER TABLE chatoperator ADD vcavatar varchar(255) " , $link );
}
if ( in_array ( " chatoperator.vcjabbername " , $absent ) ) {
runsql ( " ALTER TABLE chatoperator ADD vcjabbername varchar(255) " , $link );
}
2009-08-19 03:29:05 +04:00
if ( in_array ( " chatoperator.vcemail " , $absent ) ) {
runsql ( " ALTER TABLE chatoperator ADD vcemail varchar(64) " , $link );
}
2009-03-23 00:22:51 +03:00
if ( in_array ( " chatthread.groupid " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD groupid int references chatgroup(groupid) " , $link );
2009-01-03 04:23:19 +03:00
}
2008-10-03 19:11:02 +04:00
if ( in_array ( " chatthread.userAgent " , $absent ) ) {
runsql ( " ALTER TABLE chatthread ADD userAgent varchar(255) " , $link );
}
2009-08-19 03:29:05 +04:00
if ( in_array ( " chatgroup.vcemail " , $absent ) ) {
runsql ( " ALTER TABLE chatgroup ADD vcemail varchar(64) " , $link );
}
2009-07-24 11:37:58 +04:00
$res = mysql_query ( " select null from information_schema.statistics where table_name = 'chatmessage' and index_name = 'idx_agentid' " , $link );
if ( $res && mysql_num_rows ( $res ) == 0 ) {
2008-09-30 03:07:06 +04:00
runsql ( " ALTER TABLE chatmessage ADD INDEX idx_agentid (agentid) " , $link );
}
2007-10-17 14:43:34 +04:00
}
}
mysql_close ( $link );
2008-06-05 03:35:11 +04:00
header ( " Location: $webimroot /install/index.php " );
2007-10-17 14:43:34 +04:00
exit ;
?>