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
*
2011-02-16 03:22:22 +03:00
* Copyright ( c ) 2005 - 2011 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
2011-02-26 16:57:23 +03:00
function runsql ( $query , $link )
{
2011-04-07 02:31:22 +04:00
$res = mysql_query ( $query , $link ) or show_install_err ( ' Query failed: ' . mysql_error ( $link ));
2008-09-30 03:07:06 +04:00
return $res ;
2007-10-17 14:43:34 +04:00
}
2011-02-26 16:57:23 +03:00
$act = verifyparam ( " act " , " /^(silentcreateall|createdb|ct|dt|addcolumns) $ / " );
2009-05-31 19:29:55 +04:00
2011-02-26 16:57:23 +03:00
$link = @ mysql_connect ( $mysqlhost , $mysqllogin , $mysqlpass )
2011-04-07 02:31:22 +04:00
or show_install_err ( 'Could not connect: ' . mysql_error ());
2007-10-17 14:43:34 +04:00
2008-09-30 03:07:06 +04:00
if ( $act == " silentcreateall " ) {
2011-02-26 16:57:23 +03:00
mysql_query ( " CREATE DATABASE $mysqldb " , $link ) or show_install_err ( ' Query failed: ' . mysql_error ( $link ));
foreach ( $dbtables as $id ) {
2008-09-30 03:07:06 +04:00
create_table ( $id , $link );
2011-02-26 16:57:23 +03:00
}
} else if ( $act == " createdb " ) {
mysql_query ( " CREATE DATABASE $mysqldb " , $link ) or show_install_err ( ' Query failed: ' . mysql_error ( $link ));
2007-10-17 14:43:34 +04:00
} else {
2011-02-26 16:57:23 +03:00
mysql_select_db ( $mysqldb , $link ) or show_install_err ( 'Could not select database' );
if ( $force_charset_in_connection ) {
2007-10-17 14:43:34 +04:00
mysql_query ( " SET character set $dbencoding " , $link );
}
2008-09-30 03:07:06 +04:00
2011-02-26 16:57:23 +03:00
if ( $act == " ct " ) {
2007-10-17 14:43:34 +04:00
$curr_tables = get_tables ( $link );
2011-02-26 16:57:23 +03:00
if ( $curr_tables === false ) {
2007-10-17 14:43:34 +04:00
show_install_err ( $errors [ 0 ]);
}
$tocreate = array_diff ( array_keys ( $dbtables ), $curr_tables );
2011-02-26 16:57:23 +03:00
foreach ( $tocreate as $id ) {
2007-10-17 14:43:34 +04:00
create_table ( $id , $link );
}
2011-02-26 16:57:23 +03:00
} else if ( $act == " dt " ) {
2011-03-05 01:01:24 +03:00
# comment this line to be able to drop tables
show_install_err ( " For security reasons, removing tables is disabled by default " );
2011-02-26 16:57:23 +03:00
foreach ( array_keys ( $dbtables ) as $id ) {
mysql_query ( " DROP TABLE IF EXISTS $id " , $link ) or show_install_err ( ' Query failed: ' . mysql_error ( $link ));
2008-09-30 03:07:06 +04:00
}
2011-02-26 16:57:23 +03:00
} else if ( $act == " addcolumns " ) {
2012-02-26 18:00:24 +04:00
// Add absent columns
$absent_columns = array ();
2011-02-26 16:57:23 +03:00
foreach ( $dbtables as $id => $columns ) {
2007-10-17 14:43:34 +04:00
$curr_columns = get_columns ( $id , $link );
2011-02-26 16:57:23 +03:00
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 );
2011-02-26 16:57:23 +03:00
foreach ( $tocreate as $v ) {
2012-02-26 18:00:24 +04:00
$absent_columns [] = " $id . $v " ;
2007-10-17 14:43:34 +04:00
}
}
2008-09-30 03:07:06 +04:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatmessage.agentId " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind " , $link );
2011-04-07 02:31:22 +04:00
runsql ( " update ${ mysqlprefix } chatmessage, ${ mysqlprefix } 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
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.agentId " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName " , $link );
2011-04-07 02:31:22 +04:00
runsql ( " update ${ mysqlprefix } chatthread, ${ mysqlprefix } 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
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.dtmchatstarted " , $absent_columns )) {
2011-11-19 18:23:04 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD dtmchatstarted datetime DEFAULT 0 AFTER dtmcreated " , $link );
runsql ( " update ${ mysqlprefix } chatthread set dtmchatstarted = dtmcreated " , $link );
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.agentTyping " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD agentTyping int DEFAULT 0 " , $link );
2008-05-11 02:35:16 +04:00
}
2008-09-30 03:07:06 +04:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.userTyping " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD userTyping int DEFAULT 0 " , $link );
2008-05-11 02:35:16 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.messageCount " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD messageCount varchar(16) " , $link );
runsql ( " ALTER TABLE ${ mysqlprefix } chatmessage ADD INDEX idx_threadid_ikind (threadid, ikind) " , $link );
runsql ( " UPDATE ${ mysqlprefix } chatthread t SET t.messageCount = (SELECT COUNT(*) FROM ${ mysqlprefix } chatmessage WHERE ${ mysqlprefix } chatmessage.threadid = t.threadid AND ikind = 1) " , $link );
runsql ( " ALTER TABLE ${ mysqlprefix } chatmessage DROP INDEX idx_threadid_ikind " , $link );
2008-06-05 02:51:46 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.nextagent " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD nextagent int NOT NULL DEFAULT 0 " , $link );
2008-10-02 13:35:49 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.shownmessageid " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD shownmessageid int NOT NULL DEFAULT 0 " , $link );
2008-10-03 19:11:02 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.userid " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD userid varchar(255) DEFAULT \" \" " , $link );
2008-10-03 19:11:02 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.iperm " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD iperm int DEFAULT 65535 " , $link );
2008-12-08 03:34:28 +03:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.istatus " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD istatus int DEFAULT 0 " , $link );
2009-07-24 11:37:58 +04:00
}
2011-02-26 16:57:23 +03:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.idisabled " , $absent_columns )) {
2011-12-19 21:55:22 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD idisabled int DEFAULT 0 AFTER istatus " , $link );
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.vcavatar " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD vcavatar varchar(255) " , $link );
2008-10-06 02:47:09 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.vcjabbername " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD vcjabbername varchar(255) " , $link );
2008-10-06 02:47:09 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.vcemail " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD vcemail varchar(64) " , $link );
2009-08-19 03:29:05 +04:00
}
2009-09-01 02:43:30 +04:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.dtmrestore " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD dtmrestore datetime DEFAULT 0 " , $link );
2009-09-01 02:43:30 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatoperator.vcrestoretoken " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatoperator ADD vcrestoretoken varchar(64) " , $link );
2009-09-01 02:43:30 +04:00
}
2011-02-26 16:57:23 +03:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatresponses.vctitle " , $absent_columns )) {
2012-01-29 01:52:44 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatresponses ADD vctitle varchar(100) NOT NULL DEFAULT '' AFTER groupid " , $link );
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.groupid " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD groupid int references ${ mysqlprefix } chatgroup(groupid) " , $link );
2009-01-03 04:23:19 +03:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatthread.userAgent " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatthread ADD userAgent varchar(255) " , $link );
2008-10-03 19:11:02 +04:00
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatgroup.vcemail " , $absent_columns )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatgroup ADD vcemail varchar(64) " , $link );
2009-08-19 03:29:05 +04:00
}
2011-02-26 16:57:23 +03:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatgroup.iweight " , $absent_columns )) {
2012-02-15 17:56:55 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatgroup ADD iweight int DEFAULT 0 " , $link );
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatgroup.parent " , $absent_columns )) {
2012-02-24 17:52:39 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatgroup ADD parent int DEFAULT NULL AFTER groupid " , $link );
}
2012-02-26 18:00:24 +04:00
// Add absent indexes
$absent_indexes = array ();
foreach ( $dbtables_indexes as $id => $indexes ) {
$curr_indexes = get_indexes ( $id , $link );
if ( $curr_indexes === false ) {
show_install_err ( $errors [ 0 ]);
}
$tocreate = array_diff ( array_keys ( $indexes ), $curr_indexes );
foreach ( $tocreate as $i ) {
$absent_indexes [] = " $id . $i " ;
}
}
if ( in_array ( " ${ mysqlprefix } chatgroup.parent " , $absent_indexes )) {
2012-02-24 17:52:39 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatgroup ADD INDEX (parent) " , $link );
}
2012-02-26 18:05:14 +04:00
if ( in_array ( " ${ mysqlprefix } chatgroupoperator.groupid " , $absent_indexes )) {
runsql ( " ALTER TABLE ${ mysqlprefix } chatgroupoperator ADD INDEX (groupid) " , $link );
}
if ( in_array ( " ${ mysqlprefix } chatgroupoperator.operatorid " , $absent_indexes )) {
runsql ( " ALTER TABLE ${ mysqlprefix } chatgroupoperator ADD INDEX (operatorid) " , $link );
}
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatmessage.idx_agentid " , $absent_indexes )) {
2011-02-26 16:13:16 +03:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatmessage ADD INDEX idx_agentid (agentid) " , $link );
2008-09-30 03:07:06 +04:00
}
2011-04-07 12:34:04 +04:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } chatsitevisitor.threadid " , $absent_indexes )) {
2011-04-07 12:34:04 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } chatsitevisitor ADD INDEX (threadid) " , $link );
}
2011-11-23 01:57:25 +04:00
2012-02-26 18:00:24 +04:00
if ( in_array ( " ${ mysqlprefix } visitedpage.visitorid " , $absent_indexes )) {
2011-11-23 01:57:25 +04:00
runsql ( " ALTER TABLE ${ mysqlprefix } visitedpage ADD INDEX (visitorid) " , $link );
}
2012-02-26 18:00:24 +04:00
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 ;
2011-04-07 02:31:22 +04:00
?>