View source
<?php
if (function_exists('module_load_include')) {
module_load_include('module', 'ed_classified', 'ed_classified');
}
else {
require_once dirname(drupal_get_filename('module', 'ed_classified')) . '/ed_classified_module.inc';
}
module_load_include('inc', 'ed_classified', 'ed_classified_utils');
function ed_classified_install() {
$DRUPAL_VERSION = variable_get('ed_classified_drupal_version', 'UNKNOWN');
if ('UNKNOWN' == $DRUPAL_VERSION) {
if (defined('VERSION')) {
drupal_set_message(t("!module: recording Drupal version as '!version.'", array(
'!module' => ED_CLASSIFIED_MODULE_NAME,
'!version' => VERSION,
)));
variable_set('ed_classified_drupal_version', $DRUPAL_VERSION = VERSION);
}
else {
if (!empty($theme_info) && !empty($theme_info->info)) {
$DRUPAL_VERSION = $theme_info->info['core'];
drupal_set_message(t("!module: detected Drupal version is '!version' (recording).", array(
'!module' => ED_CLASSIFIED_MODULE_NAME,
'!version' => $DRUPAL_VERSION,
)));
variable_set('ed_classified_drupal_version', $DRUPAL_VERSION);
}
else {
$msg = t('!module: failed to detect Drupal version during installation (aborting install).', array(
'!module' => ED_CLASSIFIED_MODULE_NAME,
));
drupal_set_message($msg);
watchdog($msg);
return;
}
}
}
switch (reset(explode('.', $DRUPAL_VERSION))) {
case 5:
ed_classified_schema_drupal5();
break;
case 6:
case 7:
drupal_install_schema(ED_CLASSIFIED_MODULE_NAME);
break;
default:
break;
}
_ed_classified_get_vid();
}
function ed_classified_schema_drupal5() {
drupal_set_message(t('Creating classified ads table'));
$success = FALSE;
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$success = db_query("CREATE TABLE {edi_classified_nodes} (\n nid int(10) unsigned NOT NULL default '0',\n vid int(10) unsigned NOT NULL default '0',\n expires_on int(10) unsigned NOT NULL default '0' COMMENT 'Unix timestamp of expiration',\n expiration_notify_last_sent int(10) unsigned NOT NULL default '0',\n PRIMARY KEY (nid,vid));");
break;
case 'pgsql':
$success = db_query("CREATE TABLE {edi_classified_nodes} (\n nid serial CHECK (nid >=0),\n vid int_unsigned NOT NULL default '0',\n expires_on int_unsigned NOT NULL default '0',\n expiration_notify_last_sent int_unsigned NOT NULL default '0',\n PRIMARY KEY (nid));");
break;
}
if ($success) {
drupal_set_message(t('Classified module table creation successful.'));
}
else {
drupal_set_message(t('Classified module table creation was unsuccessful. Check the watchdog logs.'), 'error');
}
}
function ed_classified_schema() {
$schema['edi_classified_nodes'] = array(
'description' => 'Stores the ed_classified node-related type.',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Node nid of related node.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Node vid (version id).',
),
'expires_on' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'expiration_notify_last_sent' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'nid',
'vid',
),
);
return $schema;
}
function ed_classified_uninstall() {
switch (reset(explode('.', VERSION))) {
case 5:
db_query('DROP TABLE {edi_classified_nodes}');
db_query('DELETE FROM {vocabulary} WHERE module = "%s"', ED_CLASSIFIED_MODULE_NAME);
db_query('DELETE FROM {variable} WHERE name LIKE "ed_classified%";');
break;
case 6:
drupal_uninstall_schema(ED_CLASSIFIED_MODULE_NAME);
db_query('DELETE FROM {vocabulary} WHERE module = "%s"', ED_CLASSIFIED_MODULE_NAME);
db_query('DELETE FROM {variable} WHERE name LIKE "ed_classified%";');
break;
case 7:
drupal_uninstall_schema(ED_CLASSIFIED_MODULE_NAME);
$fields = array(
'module' => ED_CLASSIFIED_MODULE_NAME,
);
db_delete('taxonomy_vocabulary')
->fields($fields)
->execute();
$fields = array(
'name' => ED_CLASSIFIED_MODULE_NAME,
);
db_delete('variable')
->fields($fields)
->execute();
break;
}
}