View source
<?php
function nodewords_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret = db_query("CREATE TABLE {nodewords} (\n type varchar(16) NOT NULL,\n id varchar(255) NOT NULL,\n name varchar(32) NOT NULL,\n content text NULL,\n PRIMARY KEY(type, id, name)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
$ret = db_query("CREATE TABLE {nodewords} (\n type varchar(16) NOT NULL,\n id varchar(255) NOT NULL,\n name varchar(32) NOT NULL,\n content text NULL,\n PRIMARY KEY(type, id, name)\n )");
break;
}
if ($ret) {
drupal_set_message(t('Meta tags module installed succesfully.'));
}
else {
drupal_set_message(t('Meta tags module installation was unsuccesfull. The necessary database table may be created by hand. See the "README.txt" file in the "nodewords/" modules directory for instructions.', 'error'));
}
db_query("UPDATE {system} SET weight = 10 WHERE name = 'nodewords'");
return $ret;
}
function nodewords_uninstall() {
db_query("DROP TABLE {nodewords}");
variable_del('nodewords');
variable_del('nodewords-repeat');
variable_del('nodewords-use_front');
}
function _nodewords_update_create_table() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret = update_sql("CREATE TABLE {nodewords} (\n type varchar(16) NOT NULL,\n id varchar(255) NOT NULL,\n name varchar(32) NOT NULL,\n content varchar(255) NULL,\n PRIMARY KEY(type, id, name)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
$ret = update_sql("CREATE TABLE {nodewords} (\n type varchar(16) NOT NULL,\n id varchar(255) NOT NULL,\n name varchar(32) NOT NULL,\n content varchar(255) NULL,\n PRIMARY KEY(type, id, name)\n )");
break;
}
return $ret;
}
function nodewords_update_1() {
$items = array();
$keywords = variable_get('nodewords_global_keywords', '');
variable_del('nodewords_global_keywords');
$settings = variable_get('nodewords', array());
if ($keywords != '') {
$settings['global']['keywords'] = $keywords;
variable_set('nodewords', $settings);
}
$result = db_query('SELECT * FROM {nodewords} LIMIT 1');
if (db_num_rows($result) == 0) {
$items[] = update_sql('DROP TABLE {nodewords}');
$items[] = _nodewords_update_create_table();
}
else {
$row = db_fetch_array($result);
if (isset($row['nodewords'])) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$items[] = update_sql('ALTER TABLE {nodewords} ADD abstract varchar(250)');
$items[] = update_sql('ALTER TABLE {nodewords} ADD copyright varchar(250)');
$items[] = update_sql('ALTER TABLE {nodewords} ADD description varchar(250)');
$items[] = update_sql('ALTER TABLE {nodewords} CHANGE nodewords keywords varchar(250)');
break;
case 'pgsql':
$items[] = update_sql('ALTER TABLE {nodewords} ADD abstract varchar(250)');
$items[] = update_sql('ALTER TABLE {nodewords} ADD copyright varchar(250)');
$items[] = update_sql('ALTER TABLE {nodewords} ADD description varchar(250)');
$items[] = update_sql('ALTER TABLE {nodewords} RENAME nodewords TO keywords');
break;
}
}
}
return $items;
}
function nodewords_update_2() {
$items = array();
$settings = variable_get('nodewords', array());
if (isset($settings['output']) && !isset($settings['head'])) {
$settings['head'] = $settings['output'];
unset($settings['output']);
variable_set('nodewords', $settings);
}
$result = db_query('SELECT * FROM {nodewords} LIMIT 1');
if (db_num_rows($result) == 0) {
$items = update_sql('DROP TABLE {nodewords}');
$items = _nodewords_update_create_table();
}
else {
$row = db_fetch_array($result);
if (isset($row['keywords'])) {
$items[] = update_sql('CREATE TEMPORARY TABLE {nodewords_tmp} AS SELECT * FROM {nodewords}');
$items[] = update_sql('DROP TABLE {nodewords}');
$items[] = _nodewords_update_create_table();
foreach (array(
'abstract',
'copyright',
'description',
'keywords',
) as $name) {
if (isset($row[$name])) {
$items[] = update_sql("INSERT INTO {nodewords} (type, id, name, content) SELECT 'node', nid, '" . $name . "', " . $name . " FROM {nodewords_tmp} WHERE " . $name . " IS NOT NULL AND " . $name . " != ''");
}
}
$items[] = update_sql('DROP TABLE {nodewords_tmp}');
}
}
return $items;
}
function nodewords_update_3() {
return _system_update_utf8(array(
'nodewords',
));
}
function nodewords_update_4() {
$items = array();
$items[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'nodewords'");
return $items;
}
function nodewords_update_5() {
cache_clear_all();
}
function nodewords_update_6() {
global $db_type;
$items = array();
switch ($db_type) {
case 'mysql':
case 'mysqli':
$items[] = update_sql("ALTER TABLE {nodewords} CHANGE content content text;");
break;
case 'pgsql':
$items[] = update_sql("ALTER TABLE {nodewords} ALTER content TYPE text;");
break;
}
return $items;
}