From 38a4587a2d9b3fdf9458f2ac37755f672b0f9405 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Thu, 5 Jul 2001 07:38:52 +0000 Subject: [PATCH] merged addressbook tables and upgrade routines back to api, following the contacts class --- phpgwapi/setup/setup.inc.php | 2 + phpgwapi/setup/tables_baseline.inc.php | 27 ++ phpgwapi/setup/tables_current.inc.php | 72 +++++ phpgwapi/setup/tables_update.inc.php | 409 ++++++++++++++++++++++++- phpgwapi/setup/test_data.inc.php | 44 +++ 5 files changed, 543 insertions(+), 11 deletions(-) create mode 100644 phpgwapi/setup/test_data.inc.php diff --git a/phpgwapi/setup/setup.inc.php b/phpgwapi/setup/setup.inc.php index 0314ecd4f2..d0eb269428 100755 --- a/phpgwapi/setup/setup.inc.php +++ b/phpgwapi/setup/setup.inc.php @@ -33,6 +33,8 @@ $setup_info['phpgwapi']['tables'][] = 'lang'; $setup_info['phpgwapi']['tables'][] = 'languages'; $setup_info['phpgwapi']['tables'][] = 'phpgw_nextid'; + $setup_info['phpgwapi']['tables'][] = 'phpgw_addressbook'; + $setup_info['phpgwapi']['tables'][] = 'phpgw_addressbook_extra'; /* Basic information about this app */ $setup_info['notifywindow']['name'] = 'notifywindow'; diff --git a/phpgwapi/setup/tables_baseline.inc.php b/phpgwapi/setup/tables_baseline.inc.php index 9578696490..01801071d2 100644 --- a/phpgwapi/setup/tables_baseline.inc.php +++ b/phpgwapi/setup/tables_baseline.inc.php @@ -143,6 +143,33 @@ 'fk' => array(), 'ix' => array(), 'uc' => array() + ), + 'addressbook' => array( + 'fd' => array( + 'ab_id' => array('type' => 'auto', 'nullable' => false), + 'ab_owner' => array('type' => 'varchar', 'precision' => 25), + 'ab_access' => array('type' => 'varchar', 'precision' => 10), + 'ab_firstname' => array('type' => 'varchar', 'precision' => 255), + 'ab_lastname' => array('type' => 'varchar', 'precision' => 255), + 'ab_email' => array('type' => 'varchar', 'precision' => 255), + 'ab_hphone' => array('type' => 'varchar', 'precision' => 255), + 'ab_wphone' => array('type' => 'varchar', 'precision' => 255), + 'ab_fax' => array('type' => 'varchar', 'precision' => 255), + 'ab_pager' => array('type' => 'varchar', 'precision' => 255), + 'ab_mphone' => array('type' => 'varchar', 'precision' => 255), + 'ab_ophone' => array('type' => 'varchar', 'precision' => 255), + 'ab_street' => array('type' => 'varchar', 'precision' => 255), + 'ab_city' => array('type' => 'varchar', 'precision' => 255), + 'ab_state' => array('type' => 'varchar', 'precision' => 255), + 'ab_zip' => array('type' => 'varchar', 'precision' => 255), + 'ab_bday' => array('type' => 'varchar', 'precision' => 255), + 'ab_notes' => array('type' => 'text'), + 'ab_company' => array('type' => 'varchar', 'precision' => 255), + ), + 'pk' => array('ab_id'), + 'fk' => array(), + 'ix' => array(), + 'uc' => array() ) ); ?> diff --git a/phpgwapi/setup/tables_current.inc.php b/phpgwapi/setup/tables_current.inc.php index 9c9e723a33..64a8340cad 100644 --- a/phpgwapi/setup/tables_current.inc.php +++ b/phpgwapi/setup/tables_current.inc.php @@ -185,6 +185,78 @@ 'fk' => array(), 'ix' => array(), 'uc' => array() + ), + 'phpgw_addressbook' => array( + 'fd' => array( + 'id' => array('type' => 'auto','nullable' => False), + 'lid' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'tid' => array('type' => 'char', 'precision' => 1,'nullable' => True), + 'owner' => array('type' => 'int', 'precision' => 8,'nullable' => True), + 'access' => array('type' => 'varchar', 'precision' => 7,'nullable' => True), + 'cat_id' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'fn' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'n_family' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'n_given' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'n_middle' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'n_prefix' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'n_suffix' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'sound' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'bday' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'note' => array('type' => 'text','nullable' => True), + 'tz' => array('type' => 'varchar', 'precision' => 8,'nullable' => True), + 'geo' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'url' => array('type' => 'varchar', 'precision' => 128,'nullable' => True), + 'pubkey' => array('type' => 'text','nullable' => True), + 'org_name' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'org_unit' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'title' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_one_street' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_one_locality' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_one_region' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_one_postalcode' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_one_countryname' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_one_type' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'label' => array('type' => 'text','nullable' => True), + 'adr_two_street' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_two_locality' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_two_region' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_two_postalcode' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_two_countryname' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'adr_two_type' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'tel_work' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_home' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_voice' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_fax' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_msg' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_cell' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_pager' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_bbs' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_modem' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_car' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_isdn' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_video' => array('type' => 'varchar', 'precision' => 40,'nullable' => False,'default' => '+1 (000) 000-0000'), + 'tel_prefer' => array('type' => 'varchar', 'precision' => 32,'nullable' => True), + 'email' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'email_type' => array('type' => 'varchar', 'precision' => 32,'nullable' => False,'default' => 'INTERNET'), + 'email_home' => array('type' => 'varchar', 'precision' => 64,'nullable' => True), + 'email_home_type' => array('type' => 'varchar', 'precision' => 32,'nullable' => False,'default' => 'INTERNET') + ), + 'pk' => array('id'), + 'fk' => array(), + 'ix' => array(), + 'uc' => array() + ), + 'phpgw_addressbook_extra' => array( + 'fd' => array( + 'contact_id' => array('type' => 'int', 'precision' => 4, 'nullable' => True), + 'contact_owner' => array('type' => 'int', 'precision' => 8,'nullable' => True), + 'contact_name' => array('type' => 'varchar', 'precision' => 255,'nullable' => True), + 'contact_value' => array('type' => 'text','nullable' => True) + ), + 'pk' => array(), + 'fk' => array(), + 'ix' => array(), + 'uc' => array() ) ); ?> diff --git a/phpgwapi/setup/tables_update.inc.php b/phpgwapi/setup/tables_update.inc.php index 606fb54f22..e74cf82976 100644 --- a/phpgwapi/setup/tables_update.inc.php +++ b/phpgwapi/setup/tables_update.inc.php @@ -21,6 +21,10 @@ $phpgw_setup->oProc->query("update lang set lang='da' where lang='dk'"); $phpgw_setup->oProc->query("update lang set lang='ko' where lang='kr'"); + $phpgw_setup->oProc->AddColumn('addressbook', 'ab_company_id', array('type' => 'int', 'precision' => 4)); + $phpgw_setup->oProc->AddColumn('addressbook', 'ab_title', array('type' => 'varchar', 'precision' => 60)); + $phpgw_setup->oProc->AddColumn('addressbook', 'ab_address2', array('type' => 'varchar', 'precision' => 60)); + $phpgw_setup->oProc->query("update preferences set preference_name='da' where preference_name='dk'"); $phpgw_setup->oProc->query("update preferences set preference_name='ko' where preference_name='kr'"); @@ -138,6 +142,8 @@ $phpgw_setup->oProc->query("insert into applications (app_name, app_title, app_enabled, app_order, app_tables, app_version) values ('transy', 'Translation Management', 0, 13, NULL, '".$setup_info['phpgwapi']['version']."')"); + $phpgw_setup->oProc->AddColumn('addressbook', 'ab_url', array('type' => 'varchar', 'precision' => 255)); + $setup_info['phpgwapi']['currentver'] = '0.9.3pre7'; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1046,6 +1052,29 @@ } $phpgw_setup->oProc->DropTable('groups'); + + /* Moved back from addressbook */ + $phpgw_setup->oProc->query('SELECT oldid,newid FROM phpgw_temp_groupmap',__LINE__,__FILE__); + if($phpgw_setup->oProc->num_rows()) + { + while($phpgw_setup->oProc->next_record()) + { + $old_group_id = $phpgw_setup->oProc->f(0); + $new_group_id = $phpgw_setup->oProc->f(1); + $db2->query("SELECT ab_access,ab_id FROM addressbook WHERE ab_access LIKE '%,".$old_group_id.",%'",__LINE__,__FILE__); + if($db2->num_rows()) + { + while($db2->next_record()) + { + $access = $db2->f('cat_access'); + $id = $db2->f('cat_id'); + $access = str_replace(','.$old_group_id.',' , ','.$new_group_id.',' , $access); + $db3->query("UPDATE phpgw_categories SET cat_access='".$access."' WHERE cat_id=".$id,__LINE__,__FILE__); + } + } + } + } + $setup_info["phpgwapi"]["currentver"] = "0.9.10pre5"; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1165,16 +1194,206 @@ $test[] = '0.9.10pre12'; function phpgwapi_upgrade0_9_10pre12() { - global $setup_info; + global $setup_info, $phpgw_setup; + + $db1 = $phpgw_setup->db; + + $phpgw_setup->oProc->CreateTable( + 'phpgw_addressbook', array( + 'fd' => array( + 'id' => array('type' => 'auto', 'nullable' => False), + 'lid' => array('type' => 'varchar', 'precision' => 32), + 'tid' => array('type' => 'char', 'precision' => 1), + 'owner' => array('type' => 'int', 'precision' => 4), + 'fn' => array('type' => 'varchar', 'precision' => 64), + 'sound' => array('type' => 'varchar', 'precision' => 64), + 'org_name' => array('type' => 'varchar', 'precision' => 64), + 'org_unit' => array('type' => 'varchar', 'precision' => 64), + 'title' => array('type' => 'varchar', 'precision' => 64), + 'n_family' => array('type' => 'varchar', 'precision' => 64), + 'n_given' => array('type' => 'varchar', 'precision' => 64), + 'n_middle' => array('type' => 'varchar', 'precision' => 64), + 'n_prefix' => array('type' => 'varchar', 'precision' => 64), + 'n_suffix' => array('type' => 'varchar', 'precision' => 64), + 'label' => array('type' => 'text'), + 'adr_poaddr' => array('type' => 'varchar', 'precision' => 64), + 'adr_extaddr' => array('type' => 'varchar', 'precision' => 64), + 'adr_street' => array('type' => 'varchar', 'precision' => 64), + 'adr_locality' => array('type' => 'varchar', 'precision' => 32), + 'adr_region' => array('type' => 'varchar', 'precision' => 32), + 'adr_postalcode' => array('type' => 'varchar', 'precision' => 32), + 'adr_countryname' => array('type' => 'varchar', 'precision' => 32), + 'adr_work' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'adr_home' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'adr_parcel' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'adr_postal' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'tz' => array('type' => 'varchar', 'precision' => 8), + 'geo' => array('type' => 'varchar', 'precision' => 32), + 'a_tel' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'a_tel_work' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'a_tel_home' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'a_tel_voice' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'a_tel_msg' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'a_tel_fax' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'a_tel_prefer' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'b_tel' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'b_tel_work' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'b_tel_home' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'b_tel_voice' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'b_tel_msg' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'b_tel_fax' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'b_tel_prefer' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'c_tel' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'c_tel_work' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'c_tel_home' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'c_tel_voice' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'c_tel_msg' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'c_tel_fax' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'c_tel_prefer' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'd_emailtype' => array('type' => 'varchar', 'precision' => 32), + 'd_email' => array('type' => 'varchar', 'precision' => 64), + 'd_email_work' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False), + 'd_email_home' => array('type' => 'char', 'precision' => '1', 'default' => 'n', 'nullable' => False) + ), + 'pk' => array('id'), + 'fk' => array(), + 'ix' => array(), + 'uc' => array('id') + ) + ); + + $phpgw_setup->oProc->CreateTable( + 'phpgw_addressbook_extra', array( + 'fd' => array( + 'contact_id' => array('type' => 'int', 'precision' => 4), + 'contact_owner' => array('type' => 'int', 'precision' => 4), + 'contact_name' => array('type' => 'varchar', 'precision' => 255), + 'contact_value' => array('type' => 'varchar', 'precision' => 255) + ), + 'pk' => array(), + 'fk' => array(), + 'ix' => array(), + 'uc' => array() + ) + ); + + $phpgw_setup->oProc->query("SELECT * FROM addressbook"); + echo '
numrows: ' . $phpgw_setup->oProc->num_rows; + + while ($phpgw_setup->oProc->next_record()) + { + $fields = $extra = array(); + + $fields['id'] = $phpgw_setup->oProc->f('ab_id'); + $fields['owner'] = addslashes($phpgw_setup->oProc->f('ab_owner')); + $fields['n_given'] = addslashes($phpgw_setup->oProc->f('ab_firstname')); + $fields['n_family'] = addslashes($phpgw_setup->oProc->f('ab_lastname')); + $fields['d_email'] = addslashes($phpgw_setup->oProc->f('ab_email')); + $fields['b_tel'] = addslashes($phpgw_setup->oProc->f('ab_hphone')); + $fields['a_tel'] = addslashes($phpgw_setup->oProc->f('ab_wphone')); + $fields['c_tel'] = addslashes($phpgw_setup->oProc->f('ab_fax')); + $fields['fn'] = addslashes($phpgw_setup->oProc->f('ab_firstname').' '.$phpgw_setup->oProc->f('ab_lastname')); + $fields['a_tel_work'] = 'y'; + $fields['b_tel_home'] = 'y'; + $fields['c_tel_fax'] = 'y'; + $fields['org_name'] = addslashes($phpgw_setup->oProc->f('ab_company')); + $fields['title'] = addslashes($phpgw_setup->oProc->f('ab_title')); + $fields['adr_street'] = addslashes($phpgw_setup->oProc->f('ab_street')); + $fields['adr_locality'] = addslashes($phpgw_setup->oProc->f('ab_city')); + $fields['adr_region'] = addslashes($phpgw_setup->oProc->f('ab_state')); + $fields['adr_postalcode'] = addslashes($phpgw_setup->oProc->f('ab_zip')); + + $extra['pager'] = $phpgw_setup->oProc->f('ab_pager'); + $extra['mphone'] = $phpgw_setup->oProc->f('ab_mphone'); + $extra['ophone'] = $phpgw_setup->oProc->f('ab_ophone'); + $extra['bday'] = $phpgw_setup->oProc->f('ab_bday'); + $extra['notes'] = $phpgw_setup->oProc->f('ab_notes'); + $extra['address2'] = $phpgw_setup->oProc->f('ab_address2'); + $extra['url'] = $phpgw_setup->oProc->f('ab_url'); + + $sql = "INSERT INTO phpgw_addressbook (org_name,n_given,n_family,fn,d_email,title,a_tel,a_tel_work," + . "b_tel,b_tel_home,c_tel,c_tel_fax,adr_street,adr_locality,adr_region,adr_postalcode,owner)" + . " VALUES ('".$fields['org_name']."','".$fields['n_given']."','".$fields['n_family']."','" + . $fields['fn']."','".$fields['d_email']."','".$fields['title']."','".$fields['a_tel']."','" + . $fields['a_tel_work']."','".$fields['b_tel']."','".$fields['b_tel_home']."','" + . $fields['c_tel']."','".$fields['c_tel_fax']."','".$fields['adr_street']."','" + . $fields['adr_locality']."','".$fields['adr_region']."','".$fields['adr_postalcode']."','" + . $fields['owner'] ."')"; + + $db1->query($sql); + + while (list($name,$value) = each($extra)) + { + $sql = "INSERT INTO phpgw_addressbook_extra VALUES ('".$fields['id']."','" . $fields['owner'] . "','" + . addslashes($name) . "','" . addslashes($value) . "')"; + $db1->query($sql); + } + } $setup_info['phpgwapi']['currentver'] = '0.9.10pre13'; return $setup_info['phpgwapi']['currentver']; //return True; + // Note we are still leaving the old addressbook table alone here... for third party apps if they need it } $test[] = '0.9.10pre13'; function phpgwapi_upgrade0_9_10pre13() { - global $setup_info; + global $setup_info, $phpgw_setup; + + $db1 = $phpgw_setup->db; + + $phpgw_setup->oProc->AddColumn('phpgw_addressbook', 'url', array('type' => 'varchar', 'precision' => 128)); + $phpgw_setup->oProc->AddColumn('phpgw_addressbook', 'bday', array('type' => 'varchar', 'precision' => 32)); + $phpgw_setup->oProc->AddColumn('phpgw_addressbook', 'note', array('type' => 'text')); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook_extra', 'contact_value', array('type' => 'text')); + + $sql = "SELECT * FROM phpgw_addressbook_extra WHERE contact_name='url'"; + $phpgw_setup->oProc->query($sql,__LINE__,__FILE__); + + while($phpgw_setup->oProc->next_record()) + { + $cid = $phpgw_setup->oProc->f('contact_id'); + $cvalu = $phpgw_setup->oProc->f('contact_value'); + if ($cid && $cvalu) + { + $update = "UPDATE phpgw_addressbook SET url='" . $cvalu . "' WHERE id=" . $cid; + $db1->query($update); + $delete = "DELETE FROM phpgw_addressbook_extra WHERE contact_id=" . $cid . " AND contact_name='url'"; + $db1->query($delete); + } + } + + $sql = "SELECT * FROM phpgw_addressbook_extra WHERE contact_name='bday'"; + $phpgw_setup->oProc->query($sql,__LINE__,__FILE__); + + while($phpgw_setup->oProc->next_record()) + { + $cid = $phpgw_setup->oProc->f('contact_id'); + $cvalu = $phpgw_setup->oProc->f('contact_value'); + if ($cid && $cvalu) + { + $update = "UPDATE phpgw_addressbook set bday='" . $cvalu . "' WHERE id=" . $cid; + $db1->query($update); + $delete = "DELETE FROM phpgw_addressbook_extra WHERE contact_id=" . $cid . " AND contact_name='bday'"; + $db1->query($delete); + } + } + + $sql = "SELECT * FROM phpgw_addressbook_extra WHERE contact_name='notes'"; + $phpgw_setup->oProc->query($sql,__LINE__,__FILE__); + + while($phpgw_setup->oProc->next_record()) + { + $cid = $phpgw_setup->oProc->f('contact_id'); + $cvalu = $phpgw_setup->oProc->f('contact_value'); + if ($cvalu) + { + $update = "UPDATE phpgw_addressbook set note='" . $cvalu . "' WHERE id=" . $cid; + $db1->query($update); + $delete = "DELETE FROM phpgw_addressbook_extra WHERE contact_id=" . $cid . " AND contact_name='notes'"; + $db1->query($delete); + } + } $setup_info['phpgwapi']['currentver'] = '0.9.10pre14'; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1195,16 +1414,172 @@ $test[] = '0.9.10pre15'; function phpgwapi_upgrade0_9_10pre15() { - global $setup_info; - $setup_info['phpgwapi']['currentver'] = '0.9.10pre16'; - return $setup_info['phpgwapi']['currentver']; + global $setup_info, $phpgw_setup; + + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'adr_work', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'adr_home', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'adr_parcel', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'adr_postal', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'a_tel_work', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'a_tel_home', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'a_tel_voice', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'a_tel_msg', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'a_tel_fax', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'a_tel_prefer', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'b_tel_work', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'b_tel_home', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'b_tel_voice', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'b_tel_msg', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'b_tel_fax', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'b_tel_prefer', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'c_tel_work', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'c_tel_home', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'c_tel_voice', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'c_tel_msg', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'c_tel_fax', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'c_tel_prefer', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'd_email_work', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + $phpgw_setup->oProc->AlterColumn('phpgw_addressbook', 'd_email_home', array('type' => 'char', 'precision' => 1, 'default' => 'n', 'nullable' => False)); + + $setup_info['addressbook']['currentver'] = '0.9.10pre16'; + return $setup_info['addressbook']['currentver']; //return True; } $test[] = '0.9.10pre16'; function phpgwapi_upgrade0_9_10pre16() { - global $setup_info; + global $setup_info, $phpgw_setup; + + $db1 = $phpgw_setup->db; + + $phpgw_setup->oProc->RenameTable('phpgw_addressbook', 'phpgw_addressbook_old'); + $phpgw_setup->oProc->CreateTable( + 'phpgw_addressbook', array( + 'fd' => array( + 'id' => array('type' => 'auto', 'nullable' => False), + 'lid' => array('type' => 'varchar', 'precision' => 32), + 'tid' => array('type' => 'char', 'precision' => 1), + 'owner' => array('type' => 'int', 'precision' => 4), + 'fn' => array('type' => 'varchar', 'precision' => 64), + 'n_family' => array('type' => 'varchar', 'precision' => 64), + 'n_given' => array('type' => 'varchar', 'precision' => 64), + 'n_middle' => array('type' => 'varchar', 'precision' => 64), + 'n_prefix' => array('type' => 'varchar', 'precision' => 64), + 'n_suffix' => array('type' => 'varchar', 'precision' => 64), + 'sound' => array('type' => 'varchar', 'precision' => 64), + 'bday' => array('type' => 'varchar', 'precision' => 32), + 'note' => array('type' => 'text'), + 'tz' => array('type' => 'varchar', 'precision' => 8), + 'geo' => array('type' => 'varchar', 'precision' => 32), + 'url' => array('type' => 'varchar', 'precision' => 128), + 'org_name' => array('type' => 'varchar', 'precision' => 64), + 'org_unit' => array('type' => 'varchar', 'precision' => 64), + 'title' => array('type' => 'varchar', 'precision' => 64), + 'adr_one_street' => array('type' => 'varchar', 'precision' => 64), + 'adr_one_locality' => array('type' => 'varchar', 'precision' => 32), + 'adr_one_region' => array('type' => 'varchar', 'precision' => 32), + 'adr_one_postalcode' => array('type' => 'varchar', 'precision' => 32), + 'adr_one_countryname' => array('type' => 'varchar', 'precision' => 32), + 'adr_one_type' => array('type' => 'varchar', 'precision' => 64), + 'label' => array('type' => 'text'), + 'adr_two_street' => array('type' => 'varchar', 'precision' => 64), + 'adr_two_locality' => array('type' => 'varchar', 'precision' => 32), + 'adr_two_region' => array('type' => 'varchar', 'precision' => 32), + 'adr_two_postalcode' => array('type' => 'varchar', 'precision' => 32), + 'adr_two_type' => array('type' => 'varchar', 'precision' => 64), + 'tel_work' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_home' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_voice' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_fax' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_msg' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_cell' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_pager' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_bbs' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_modem' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_car' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_isdn' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_video' => array('type' => 'varchar', 'precision' => 40, 'default' => '+1 (000) 000-0000', 'nullable' => False), + 'tel_prefer' => array('type' => 'varchar', 'precision' => 32), + 'email' => array('type' => 'varchar', 'precision' => 64), + 'email_type' => array('type' => 'varchar', 'precision' => 32, 'default' => 'INTERNET'), + 'email_home' => array('type' => 'varchar', 'precision' => 64), + 'email_home_type' => array('type' => 'varchar', 'precision' => 32, 'default' => 'INTERNET') + ), + 'pk' => array('id'), + 'fk' => array(), + 'ix' => array(), + 'uc' => array() + ) + ); + + $phpgw_setup->oProc->query("SELECT * FROM phpgw_addressbook_old"); + while ($phpgw_setup->oProc->next_record()) + { + $fields['id'] = $phpgw_setup->oProc->f("id"); + $fields['owner'] = $phpgw_setup->oProc->f("owner"); + $fields['n_given'] = $phpgw_setup->oProc->f("firstname"); + $fields['n_family'] = $phpgw_setup->oProc->f("lastname"); + $fields['email'] = $phpgw_setup->oProc->f("d_email"); + $fields['email_type'] = $phpgw_setup->oProc->f("d_emailtype"); + $fields['tel_home'] = $phpgw_setup->oProc->f("b_tel"); + $fields['tel_work'] = $phpgw_setup->oProc->f("a_tel"); + $fields['tel_fax'] = $phpgw_setup->oProc->f("c_tel"); + $fields['fn'] = $phpgw_setup->oProc->f("fn"); + $fields['org_name'] = $phpgw_setup->oProc->f("org_name"); + $fields['title'] = $phpgw_setup->oProc->f("title"); + $fields['adr_one_street'] = $phpgw_setup->oProc->f("adr_street"); + $fields['adr_one_locality'] = $phpgw_setup->oProc->f("adr_locality"); + $fields['adr_one_region'] = $phpgw_setup->oProc->f("adr_region"); + $fields['adr_one_postalcode'] = $phpgw_setup->oProc->f("adr_postalcode"); + $fields['adr_one_countryname'] = $phpgw_setup->oProc->f("adr_countryname"); + $fields['bday'] = $phpgw_setup->oProc->f("bday"); + $fields['note'] = $phpgw_setup->oProc->f("note"); + $fields['url'] = $phpgw_setup->oProc->f("url"); + + $sql="INSERT INTO phpgw_addressbook (org_name,n_given,n_family,fn,email,email_type,title,tel_work," + . "tel_home,tel_fax,adr_one_street,adr_one_locality,adr_one_region,adr_one_postalcode,adr_one_countryname," + . "owner,bday,url,note)" + . " VALUES ('".$fields["org_name"]."','".$fields["n_given"]."','".$fields["n_family"]."','" + . $fields["fn"]."','".$fields["email"]."','".$fields["email_type"]."','".$fields["title"]."','".$fields["tel_work"]."','" + . $fields["tel_home"]."','".$fields["tel_fax"] ."','".$fields["adr_one_street"]."','" + . $fields["adr_one_locality"]."','".$fields["adr_one_region"]."','".$fields["adr_one_postalcode"]."','" + . $fields["adr_one_countryname"]."','".$fields["owner"] ."','".$fields["bday"]."','".$fields["url"]."','".$fields["note"]."')"; + + $db1->query($sql,__LINE__,__FILE__); + } + + $phpgw_setup->oProc->query("DROP TABLE phpgw_addressbook_old"); + + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_home='' WHERE tel_home='n' OR tel_home='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_work='' WHERE tel_work='n' OR tel_work='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_cell='' WHERE tel_cell='n' OR tel_cell='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_voice='' WHERE tel_voice='n' OR tel_voice='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_fax='' WHERE tel_fax='n' OR tel_fax='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_car='' WHERE tel_car='n' OR tel_car='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_pager='' WHERE tel_pager='n' OR tel_pager='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_msg='' WHERE tel_msg='n' OR tel_msg='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_bbs='' WHERE tel_bbs='n' OR tel_bbs='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_modem='' WHERE tel_modem='n' OR tel_modem='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_prefer='' WHERE tel_prefer='n' OR tel_prefer='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_video='' WHERE tel_video='n' OR tel_video='y'"); + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tel_isdn='' WHERE tel_isdn='n' OR tel_isdn='y'"); + + $sql = "SELECT * FROM phpgw_addressbook_extra WHERE contact_name='mphone'"; + $phpgw_setup->oProc->query($sql,__LINE__,__FILE__); + + while($phpgw_setup->oProc->next_record()) + { + $cid = $phpgw_setup->oProc->f('contact_id'); + $cvalu = $phpgw_setup->oProc->f('contact_value'); + if ($cvalu) + { + $update = "UPDATE phpgw_addressbook SET tel_cell='" . $cvalu . "' WHERE id=" . $cid; + $db1->query($update); + $delete = "DELETE FROM phpgw_addressbook_extra WHERE contact_id=" . $cid . " AND contact_name='mphone'"; + $db1->query($delete); + } + } $setup_info['phpgwapi']['currentver'] = '0.9.10pre17'; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1213,7 +1588,11 @@ $test[] = '0.9.10pre17'; function phpgwapi_upgrade0_9_10pre17() { - global $setup_info; + global $phpgw_info, $phpgw_setup; + + $phpgw_setup->oProc->AddColumn('phpgw_addressbook','pubkey', array('type' => 'text')); + $phpgw_setup->oProc->AddColumn('phpgw_addressbook','adr_two_countryname', array('type' => 'varchar', 'precision' => 32)); + $setup_info['phpgwapi']['currentver'] = '0.9.10pre18'; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1266,11 +1645,13 @@ return $setup_info['phpgwapi']['currentver']; //return True; } - $test[] = '0.9.10pre20'; function phpgwapi_upgrade0_9_10pre20() { - global $setup_info; + global $setup_info, $phpgw_setup; + + $phpgw_setup->oProc->AddColumn('phpgw_addressbook', 'access', array('type' => 'char', 'precision' => 7)); + $setup_info['phpgwapi']['currentver'] = '0.9.10pre21'; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1279,7 +1660,10 @@ $test[] = '0.9.10pre21'; function phpgwapi_upgrade0_9_10pre21() { - global $setup_info; + global $setup_info, $phpgw_setup; + + $phpgw_setup->oProc->AddColumn('phpgw_addressbook', 'cat_id', array('type' => 'varchar', 'precision' => 32)); + $setup_info['phpgwapi']['currentver'] = '0.9.10pre22'; return $setup_info['phpgwapi']['currentver']; //return True; @@ -1297,7 +1681,10 @@ $test[] = '0.9.10pre23'; function phpgwapi_upgrade0_9_10pre23() { - global $setup_info; + global $setup_info, $phpgw_setup; + + $phpgw_setup->oProc->query("UPDATE phpgw_addressbook SET tid='n' WHERE tid is null"); + $setup_info['phpgwapi']['currentver'] = '0.9.10pre24'; return $setup_info['phpgwapi']['currentver']; //return True; diff --git a/phpgwapi/setup/test_data.inc.php b/phpgwapi/setup/test_data.inc.php new file mode 100644 index 0000000000..e4372fe6f0 --- /dev/null +++ b/phpgwapi/setup/test_data.inc.php @@ -0,0 +1,44 @@ +query("INSERT INTO addressbook ( + ab_owner,ab_access,ab_firstname,ab_lastname, + ab_email,ab_hphone,ab_wphone,ab_fax,ab_pager, + ab_mphone,ab_ophone,ab_street,ab_city,ab_state,ab_zip, + ab_bday,ab_notes,ab_company) + VALUES(500,'private','John','Doe', + 'jdoe@yahoo.com','212-555-5555','212-555-4444','212-555-4445','212-555-5556', + '212-555-5557','212-555-5558','1234 Elm','Anytown','New York','01010', + '12/25/1970','This is a test note\nfor verification','ClearRiver Tech.')"); + + $oProc->query("INSERT INTO addressbook ( + ab_owner,ab_access,ab_firstname,ab_lastname, + ab_email,ab_hphone,ab_wphone,ab_fax,ab_pager, + ab_mphone,ab_ophone,ab_street,ab_city,ab_state,ab_zip, + ab_bday,ab_notes,ab_company) + VALUES(502,'public','Jane','Smith', + 'jane.smith@motherearth.org','212-555-5555','212-555-4444','212-555-4445','212-555-5556', + '212-555-5557','212-555-5558','1313 Mockingbird Ln.','Hooterville','Kentucky','54874', + '01/01/1983','This is a test note\nfor verification','Jasper Automotive')"); + + $oProc->query("INSERT INTO addressbook ( + ab_owner,ab_access,ab_firstname,ab_lastname, + ab_email,ab_hphone,ab_wphone,ab_fax,ab_pager, + ab_mphone,ab_ophone,ab_street,ab_city,ab_state,ab_zip, + ab_bday,ab_notes,ab_company) + VALUES(1,'private','Steven','Wright', + 'jdoe@yahoo.com','212-555-5555','212-555-4444','212-555-4445','212-555-5556', + '212-555-5557','212-555-5558','321 Contact','Oiforgot','North Dakota','15421', + '10/05/1955','This is a test note\nfor verification','Baubles and Beads')"); + +?>