hosting_client.install in Hosting 5
File
client/hosting_client.install
View source
<?php
function hosting_client_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {hosting_client} (\n vid int(10) unsigned NOT NULL default '0',\n nid int(10) unsigned NOT NULL default '0',\n name longtext,\n organization longtext,\n email varchar(255) NOT NULL default '',\n PRIMARY KEY (vid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE UNIQUE INDEX hosting_client_email_idx ON hosting_client (email)");
db_query("CREATE TABLE {hosting_client_user} (\n user int(10) unsigned NOT NULL default '0',\n client int(10) unsigned NOT NULL default '0',\n contact_type longtext NOT NULL,\n PRIMARY KEY (user, client)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("INSERT INTO {hosting_client_user} VALUES (1, 1, 'admin')");
break;
}
}
function hosting_client_update_1() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret = array();
$result = db_query("SELECT email, count(distinct nid) as count FROM {hosting_client} GROUP BY email");
while ($distinct = db_fetch_object($result)) {
if ($distinct->count > 1) {
$result2 = db_query("SELECT nid FROM {hosting_client} WHERE email = '%s' ORDER BY nid", $distinct->email);
$first = false;
while ($client = db_fetch_object($result2)) {
if (!$first) {
$first = $client->nid;
}
else {
db_query("UPDATE {hosting_site} SET client=%d WHERE client=%d", $first, $client->nid);
node_delete($client->nid);
}
}
}
}
$ret[] = update_sql("CREATE UNIQUE INDEX hosting_client_email_idx ON hosting_client (email)");
break;
}
return $ret;
}
function hosting_client_update_2() {
$ret = array();
$ret[] = update_sql("CREATE TABLE {hosting_client_user} (\n user int(10) unsigned NOT NULL default '0',\n client int(10) unsigned NOT NULL default '0',\n PRIMARY KEY (user)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
$ret[] = update_sql("INSERT INTO {hosting_client_user} VALUES (1, 1)");
node_access_rebuild();
return $ret;
}
function hosting_client_update_3() {
$ret = array();
node_access_rebuild();
return $ret;
}
function hosting_client_update_4() {
$ret = array();
node_access_rebuild();
return $ret;
}
function hosting_client_update_5() {
$ret = array();
node_access_rebuild();
return $ret;
}
function hosting_client_update_6() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {hosting_client_user} DROP PRIMARY KEY, ADD PRIMARY KEY (user, client)");
$ret[] = update_sql("ALTER TABLE {hosting_client_user} ADD contact_type LONGTEXT NOT NULL");
node_access_rebuild();
return $ret;
}
function hosting_client_update_7() {
node_access_rebuild();
return array();
}