/[drupal]/contributions/modules/ed_classified/ed_classified.install
ViewVC logotype

Contents of /contributions/modules/ed_classified/ed_classified.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sun Sep 13 03:06:58 2009 UTC (2 months, 2 weeks ago) by milesgillham
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +84 -29 lines
File MIME type: text/x-php
stable checkin
1 <?php
2 // $Id: ed_classified.install,v 1.3 2009/09/11 04:01:36 milesgillham Exp $
3
4 /*
5 * @file
6 * Installer
7 */
8
9 define('ED_CLASSIFIED_MODULE_NAME', 'ed_classified');
10
11 function ed_classified_install() {
12 $DRUPAL_VERSION=variable_get('ed_classified_drupal_version', 'UNKNOWN');
13 if ('UNKNOWN' == $DRUPAL_VERSION) {
14 if (defined('VERSION')) {
15 drupal_set_message(t("!module: recording Drupal version as '!version.'", array('!module' => ED_CLASSIFIED_MODULE_NAME, '!version' => VERSION)));
16 variable_set('ed_classified_drupal_version', $DRUPAL_VERSION = VERSION);
17 } else {
18 if ((!empty($theme_info)) && (!empty($theme_info->info))) {
19 $DRUPAL_VERSION = $theme_info->info['core'];
20 drupal_set_message(t("!module: detected Drupal version is '!version' (recording).", array('!module' => ED_CLASSIFIED_MODULE_NAME, '!version' => $DRUPAL_VERSION)));
21 variable_set('ed_classified_drupal_version', $DRUPAL_VERSION);
22 } else {
23 $msg = t('!module: failed to detect Drupal version during installation (aborting install).', array('!module' => ED_CLASSIFIED_MODULE_NAME));
24 drupal_set_message($msg);
25 watchdog($msg);
26 return; // Give up
27 }
28 }
29 }
30 switch (reset(explode('.', $DRUPAL_VERSION))) {
31 case 5:
32 // TODO (paste in from D5.x branch
33 break;
34 case 6:
35 case 7:
36 drupal_install_schema(ED_CLASSIFIED_MODULE_NAME);
37 break;
38 default:
39 break;
40 }
41 ed_classified_init_taxonomy();
42 }
43
44 /**
45 * Implementation of hook_schema().
46 * As of Drupal 7 schema tags do not need to be translated with t()
47 * Strings should be non-markup plain text
48 */
49 function ed_classified_schema() {
50 $schema['edi_classified_nodes'] = array(
51 'description' => 'Stores the ed_classified node-related type.',
52 'fields' => array(
53 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,
54 'description' => 'Node vid (version id).'),
55 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,
56 'description' => 'Node nid of related node.'),
57 'expires_on' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
58 'expiration_notify_last_sent' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)
59 ),
60 'primary key' => array('nid', 'vid'),
61 );
62
63 return $schema;
64 }
65
66 function ed_classified_init_taxonomy() {
67 $vid = variable_get('ed_classified_vocabulary', '');
68 if (empty($vid)) {
69 drupal_set_message(t('Checking classified ads taxonomy terms'));
70 $DRUPAL_VERSION=variable_get('ed_classified_drupal_version', 'UNKNOWN');
71 switch (reset(explode('.', $DRUPAL_VERSION))) {
72 case 5:
73 case 6:
74 $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='%s'", ED_CLASSIFIED_MODULE_NAME));
75 if (!$vid) {
76 $vocabulary = array('name' => 'Classified Ad Category',
77 'description' => t('Vocabulary required by Classified Ads ('.ED_CLASSIFIED_MODULE_NAME.') module. <strong>Warning: You should not delete this vocabulary unless you intend to uninstall (or have already uninstalled) the Classified Ads module.</strong>'),
78 'multiple' => '0',
79 'required' => '1',
80 'hierarchy' => '1',
81 'relations' => '0',
82 'module' => ED_CLASSIFIED_MODULE_NAME,
83 'nodes' => array(ED_CLASSIFIED_MODULE_NAME => 1));
84 taxonomy_save_vocabulary($vocabulary);
85 $vid = $vocabulary['vid'];
86 }
87 variable_set('ed_classified_vocabulary', $vid);
88 break;
89 case 7:
90 $vid = db_result(db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module='%s'", ED_CLASSIFIED_MODULE_NAME));
91 if (!$vid) {
92 $vocabulary = (object) array('name' => 'Classified Ad Category',
93 'description' => t('Vocabulary required by Classified Ads ('.ED_CLASSIFIED_MODULE_NAME.') module. <strong>Warning: You should not delete this vocabulary unless you intend to uninstall (or have already uninstalled) the Classified Ads module.</strong>'),
94 'multiple' => '0',
95 'required' => '1',
96 'hierarchy' => '1',
97 'relations' => '0',
98 'module' => ED_CLASSIFIED_MODULE_NAME,
99 'nodes' => array(ED_CLASSIFIED_MODULE_NAME => 1));
100 taxonomy_vocabulary_save($vocabulary);
101 $vid = db_result(db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module='%s'", ED_CLASSIFIED_MODULE_NAME));
102 }
103 variable_set('ed_classified_vocabulary', $vid);
104 break;
105 default:
106 drupal_set_message('Unknown Drupal version - unable to initialise vocabulary.');
107 return;
108 break; // no, this never gets here, but it "should" stay
109 }
110 $msg = t('Install: Classified Ad vocabulary !vid created.', array('!vid' => $vid));
111 drupal_set_message($msg);
112 watchdog('Classified Ads', $msg);
113 }
114 }
115
116 /**
117 * Implementation of hook_uninstall().
118 */
119 function ed_classified_uninstall() {
120 switch (reset(explode('.', VERSION))) {
121 case 5:
122 db_query('DROP TABLE {edi_classified_nodes}');
123 db_query('DELETE FROM {vocabulary} WHERE module = "%s"', ED_CLASSIFIED_MODULE_NAME);
124 db_query('DELETE FROM {variable} WHERE name LIKE "ed_classified%";');
125 break;
126 case 6:
127 drupal_uninstall_schema(ED_CLASSIFIED_MODULE_NAME);
128 db_query('DELETE FROM {vocabulary} WHERE module = "%s"', ED_CLASSIFIED_MODULE_NAME);
129 db_query('DELETE FROM {variable} WHERE name LIKE "ed_classified%";');
130 break;
131 case 7:
132 // TODO: is the schema automagically uninstalled in Drupal 7?
133 drupal_uninstall_schema(ED_CLASSIFIED_MODULE_NAME);
134 // db_query('DELETE FROM {taxonomy_vocabulary} WHERE module = "%s"', ED_CLASSIFIED_MODULE_NAME);
135 // db_query('DELETE FROM {variable} WHERE name LIKE "ed_classified%";');
136 $fields = array('module' => ED_CLASSIFIED_MODULE_NAME);
137 db_delete('taxonomy_vocabulary')->fields($fields)->execute();
138 // TODO - Drupal 7 - set up the fields to do a LIKE % ...
139 $fields = array('name' => ED_CLASSIFIED_MODULE_NAME);
140 db_delete('variable')->fields($fields)->execute();
141 break;
142 }
143 }
144

  ViewVC Help
Powered by ViewVC 1.1.2