| 1 |
<?php |
<?php |
| 2 |
// $Id: api.install,v 1.5.2.5 2007/10/20 01:39:16 drumm Exp $ |
// $Id: api.install,v 1.6 2008/05/19 07:09:38 drumm Exp $ |
| 3 |
|
|
| 4 |
function api_install() { |
function api_schema() { |
| 5 |
switch ($GLOBALS['db_type']) { |
$schema['api_branch'] = array( |
| 6 |
case 'mysql': |
'fields' => array( |
| 7 |
case 'mysqli': |
'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), |
| 8 |
db_query("CREATE TABLE {api_branch} ( |
'title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), |
| 9 |
branch_name varchar(31) NOT NULL default '', |
'directory' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), |
| 10 |
title varchar(255) NOT NULL default '', |
), |
| 11 |
directory varchar(255) NOT NULL default '', |
'primary key' => array('branch_name'), |
| 12 |
PRIMARY KEY (branch_name) |
); |
| 13 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
$schema['api_documentation'] = array( |
| 14 |
|
'fields' => array( |
| 15 |
db_query("CREATE TABLE {api_documentation} ( |
'did' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), |
| 16 |
did int(10) unsigned NOT NULL default '0', |
'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''), |
| 17 |
object_name varchar(127) NOT NULL default '', |
'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), |
| 18 |
branch_name varchar(31) NOT NULL default '', |
'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), |
| 19 |
object_type varchar(31) NOT NULL default '', |
'title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), |
| 20 |
title varchar(255) NOT NULL default '', |
'file_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''), |
| 21 |
file_name varchar(127) NOT NULL default '', |
'summary' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), |
| 22 |
summary mediumtext NOT NULL, |
'documentation' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), |
| 23 |
documentation mediumtext NOT NULL, |
'code' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), |
| 24 |
code mediumtext NOT NULL, |
), |
| 25 |
PRIMARY KEY (did), |
'primary key' => array('did'), |
| 26 |
UNIQUE KEY object_name (object_name,branch_name,object_type), |
'unique keys' => array( |
| 27 |
INDEX (branch_name), |
'object_name' => array('object_name', 'branch_name', 'object_type'), |
| 28 |
INDEX (title) |
), |
| 29 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'indexes' => array( |
| 30 |
|
'branch_name' => array('branch_name'), |
| 31 |
db_query("CREATE TABLE {api_file} ( |
'title' => array('title'), |
| 32 |
did int(10) unsigned NOT NULL default '0', |
), |
| 33 |
modified int(11) NOT NULL default '0', |
); |
| 34 |
version varchar(255) NOT NULL default '', |
$schema['api_file'] = array( |
| 35 |
found tinyint(1) UNSIGNED NOT NULL default 0, |
'fields' => array( |
| 36 |
PRIMARY KEY (did) |
'did' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), |
| 37 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'modified' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 38 |
|
'version' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), |
| 39 |
db_query("CREATE TABLE {api_function} ( |
'found' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '1'), |
| 40 |
did int(10) unsigned NOT NULL default '0', |
), |
| 41 |
signature varchar(255) NOT NULL default '', |
'primary key' => array('did'), |
| 42 |
start_line int(10) NOT NULL default '0', |
); |
| 43 |
parameters mediumtext NOT NULL, |
$schema['api_function'] = array( |
| 44 |
`return` mediumtext NOT NULL, |
'fields' => array( |
| 45 |
PRIMARY KEY (did) |
'did' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), |
| 46 |
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); |
'signature' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), |
| 47 |
|
'start_line' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), |
| 48 |
db_query("CREATE TABLE {api_reference_storage} ( |
'parameters' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), |
| 49 |
object_name varchar(127) NOT NULL default '', |
'return' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), |
| 50 |
branch_name varchar(31) NOT NULL default '', |
), |
| 51 |
object_type varchar(31) NOT NULL default '', |
'primary key' => array('did'), |
| 52 |
from_did int NOT NULL default '0', |
); |
| 53 |
to_did int NOT NULL default '0', |
$schema['api_reference_storage'] = array( |
| 54 |
INDEX object_ref (object_name,branch_name,object_type) |
'fields' => array( |
| 55 |
) /*!40100 DEFAULT CHARACTER SET utf8 */"); |
'object_name' => array('type' => 'varchar', 'length' => '127', 'not null' => TRUE, 'default' => ''), |
| 56 |
break; |
'branch_name' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), |
| 57 |
|
'object_type' => array('type' => 'varchar', 'length' => '31', 'not null' => TRUE, 'default' => ''), |
| 58 |
|
'from_did' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 59 |
|
'to_did' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), |
| 60 |
|
), |
| 61 |
|
'indexes' => array( |
| 62 |
|
'object_ref' => array('object_name', 'branch_name', 'object_type'), |
| 63 |
|
), |
| 64 |
|
); |
| 65 |
|
|
| 66 |
case 'pgsql': |
return $schema; |
| 67 |
break; |
} |
| 68 |
} |
|
| 69 |
|
function api_install() { |
| 70 |
|
drupal_install_schema('api'); |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
function api_update_1() { |
function api_update_1() { |
| 76 |
|
|
| 77 |
function api_update_2() { |
function api_update_2() { |
| 78 |
$ret = array(); |
$ret = array(); |
| 79 |
|
db_add_column($ret, 'api_file', 'found', 'tinyint', array('not null' => TRUE, 'default' => 0, 'length' => 1, 'unsigned' => TRUE)); |
|
switch ($GLOBALS['db_type']) { |
|
|
case 'pgsql': |
|
|
db_add_column($ret, 'api_file', 'found', 'smallint', array('not null' => TRUE, 'default' => 0)); |
|
|
break; |
|
|
|
|
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
$ret[] = update_sql("ALTER TABLE {api_file} ADD COLUMN found tinyint(1) UNSIGNED NOT NULL DEFAULT 0"); |
|
|
break; |
|
|
} |
|
| 80 |
|
|
| 81 |
return $ret; |
return $ret; |
| 82 |
} |
} |
| 98 |
|
|
| 99 |
function api_update_4() { |
function api_update_4() { |
| 100 |
$return = array(); |
$return = array(); |
| 101 |
|
db_add_index($return, 'api_documentation', '', 'branch_name'); |
|
switch ($GLOBALS['db_type']) { |
|
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
$return[] = update_sql('ALTER TABLE {api_documentation} ADD INDEX (branch_name)'); |
|
|
break; |
|
|
} |
|
|
|
|
| 102 |
return $return; |
return $return; |
| 103 |
} |
} |
| 104 |
|
|
| 105 |
function api_update_5() { |
function api_update_5() { |
| 106 |
$return = array(); |
$return = array(); |
| 107 |
|
db_add_index($return, 'api_documentation', '', 'title'); |
|
switch ($GLOBALS['db_type']) { |
|
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
$return[] = update_sql('ALTER TABLE {api_documentation} ADD INDEX (title)'); |
|
|
break; |
|
|
} |
|
| 108 |
|
|
| 109 |
return $return; |
return $return; |
| 110 |
} |
} |
| 115 |
*/ |
*/ |
| 116 |
function api_update_6() { |
function api_update_6() { |
| 117 |
$return = array(); |
$return = array(); |
| 118 |
|
$schema['api_reference_storage'] = array( |
| 119 |
|
'fields' => array( |
| 120 |
|
'object_name' => array( |
| 121 |
|
'type' => 'varchar', |
| 122 |
|
'length' => '127', |
| 123 |
|
'not null' => TRUE, |
| 124 |
|
'default' => '', |
| 125 |
|
), |
| 126 |
|
'branch_name' => array( |
| 127 |
|
'type' => 'varchar', |
| 128 |
|
'length' => 31, |
| 129 |
|
'not null' => TRUE, |
| 130 |
|
'default' => '', |
| 131 |
|
), |
| 132 |
|
'object_type' => array( |
| 133 |
|
'type' => 'varchar', |
| 134 |
|
'length' => 31, |
| 135 |
|
'not null' => TRUE, |
| 136 |
|
'default' => '', |
| 137 |
|
), |
| 138 |
|
'from_did' => array( |
| 139 |
|
'type' => 'int', |
| 140 |
|
'not null' => TRUE, |
| 141 |
|
'default' => '0' |
| 142 |
|
), |
| 143 |
|
'to_did' => array( |
| 144 |
|
'type' => 'int', |
| 145 |
|
'not null' => TRUE, |
| 146 |
|
'default' => '0'), |
| 147 |
|
), |
| 148 |
|
'indexes' => array( |
| 149 |
|
'api_documentation_object_ref' => array('object_name', 'branch_name', 'object_type'), |
| 150 |
|
), |
| 151 |
|
); |
| 152 |
|
|
| 153 |
switch ($GLOBALS['db_type']) { |
db_rename_table($return, 'api_reference_storage', 'api_reference_storage_old'); |
| 154 |
case 'mysql': |
db_create_table($return, 'api_reference_storage', $schema['api_reference_storage']); |
|
case 'mysqli': |
|
|
$return[] = update_sql('RENAME TABLE {api_reference_storage} TO {api_reference_storage_old}'); |
|
|
$return[] = update_sql("CREATE TABLE {api_reference_storage} ( |
|
|
object_name varchar(127) NOT NULL default '', |
|
|
branch_name varchar(31) NOT NULL default '', |
|
|
object_type varchar(31) NOT NULL default '', |
|
|
from_did int NOT NULL default '0', |
|
|
to_did int NOT NULL default '0', |
|
|
INDEX object_ref (object_name,branch_name,object_type) |
|
|
) /*!40100 DEFAULT CHARACTER SET utf8 */"); |
|
|
break; |
|
|
} |
|
| 155 |
|
|
| 156 |
$result = db_query('SELECT * FROM {api_reference_storage}'); |
$result = db_query('SELECT * FROM {api_reference_storage}'); |
| 157 |
while ($row = db_fetch_object($result)) { |
while ($row = db_fetch_object($result)) { |
| 159 |
db_query("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did) VALUES ('%s', '%s', '%s', %d)", $to_name, $branch_name, $to_type, $row->from_did); |
db_query("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did) VALUES ('%s', '%s', '%s', %d)", $to_name, $branch_name, $to_type, $row->from_did); |
| 160 |
} |
} |
| 161 |
|
|
| 162 |
switch ($GLOBALS['db_type']) { |
db_drop_table($return, 'api_reference_storage_old'); |
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
$return[] = update_sql('DROP TABLE {api_reference_storage_old}'); |
|
|
break; |
|
|
} |
|
| 163 |
|
|
| 164 |
return $return; |
return $return; |
| 165 |
} |
} |
| 170 |
function api_update_7() { |
function api_update_7() { |
| 171 |
$return = array(); |
$return = array(); |
| 172 |
|
|
| 173 |
switch ($GLOBALS['db_type']) { |
$return[] = update_sql("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did, to_did) SELECT d.object_name, d.branch_name, d.object_type, r.from_did, r.to_did FROM {api_reference} r INNER JOIN {api_documentation} d ON d.did = r.to_did"); |
| 174 |
case 'mysql': |
db_drop_table($return, 'api_reference'); |
| 175 |
case 'mysqli': |
|
| 176 |
$return[] = update_sql("INSERT INTO {api_reference_storage} (object_name, branch_name, object_type, from_did, to_did) SELECT d.object_name, d.branch_name, d.object_type, r.from_did, r.to_did FROM {api_reference} r INNER JOIN {api_documentation} d ON d.did = r.to_did"); |
return $return; |
| 177 |
$return[] = update_sql('DROP TABLE {api_reference}'); |
} |
| 178 |
break; |
|
| 179 |
} |
function api_update_8() { |
| 180 |
|
$return = array(); |
| 181 |
|
|
| 182 |
|
db_drop_primary_key($return, 'api_documentation'); |
| 183 |
|
db_change_field($return, 'api_documentation', 'did', 'did', |
| 184 |
|
array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), |
| 185 |
|
array('primary key' => array('did')) |
| 186 |
|
); |
| 187 |
|
|
| 188 |
return $return; |
return $return; |
| 189 |
} |
} |
| 190 |
|
|
| 191 |
function api_uninstall() { |
function api_uninstall() { |
| 192 |
db_query('DROP TABLE IF EXISTS {api_branch}'); |
drupal_uninstall_schema('api'); |
|
db_query('DROP TABLE IF EXISTS {api_documentation}'); |
|
|
db_query('DROP TABLE IF EXISTS {api_file}'); |
|
|
db_query('DROP TABLE IF EXISTS {api_function}'); |
|
|
db_query('DROP TABLE IF EXISTS {api_reference_storage}'); |
|
| 193 |
variable_del('api_default_branch'); |
variable_del('api_default_branch'); |
| 194 |
variable_del('api_php_funcsummary'); |
variable_del('api_php_funcsummary'); |
| 195 |
variable_del('api_php_funcpath'); |
variable_del('api_php_funcpath'); |