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

Contents of /contributions/modules/gnupg/gnupg.install

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


Revision 1.4 - (show annotations) (download) (as text)
Wed Feb 18 15:58:20 2009 UTC (9 months, 1 week ago) by arto
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +15 -5 lines
File MIME type: text/x-php
Added a {gnupg_keys.key_id} column for storing the key ID/fingerprint.
1 <?php
2 // $Id$
3
4 //////////////////////////////////////////////////////////////////////////////
5 // Core API hooks
6
7 /**
8 * Implementation of hook_enable().
9 */
10 function gnupg_enable() {
11 drupal_set_message(t('GnuPG API successfully installed. Please review the available <a href="@settings">configuration settings</a>.', array('@settings' => url('admin/settings/gnupg'))));
12 }
13
14 /**
15 * Implementation of hook_install().
16 */
17 function gnupg_install() {
18 drupal_install_schema('gnupg');
19 }
20
21 /**
22 * Implementation of hook_uninstall().
23 */
24 function gnupg_uninstall() {
25 drupal_uninstall_schema('gnupg');
26 db_query("DELETE FROM {variable} WHERE name LIKE '%s_%%'", 'gnupg');
27 cache_clear_all('variables', 'cache');
28 }
29
30 /**
31 * Implementation of hook_requirements().
32 */
33 function gnupg_requirements($phase) {
34 $status = array();
35
36 if ($phase == 'runtime') {
37 $gpg_version = gnupg_version();
38 $status['gnupg'] = array(
39 'title' => t('GnuPG'),
40 'value' => $gpg_version ? t('@version', array('@version' => (string)$gpg_version)) : t('Not available'),
41 'description' => $gpg_version ? '' : t('<a href="@gpg">GnuPG</a> is not available on the server, or the <a href="@settings">configuration settings</a> are incorrect.', array('@gpg' => 'http://www.gnupg.org/', '@settings' => url('admin/settings/gnupg'))),
42 'severity' => $gpg_version ? REQUIREMENT_OK : REQUIREMENT_ERROR,
43 );
44
45 if ($gpg_version) { // GPG is installed
46 if (!is_dir(GNUPG_HOMEDIR)) {
47 $status['gnupg_homedir'] = array(
48 'title' => t('GnuPG home directory'),
49 'value' => t('Misconfigured'),
50 'description' => t('The <a href="@gpg">GnuPG</a> home directory %directory does not exist. Make sure the <a href="@settings">configuration settings</a> are correct.', array('@gpg' => 'http://www.gnupg.org/', '%directory' => GNUPG_HOMEDIR, '@settings' => url('admin/settings/gnupg'))),
51 'severity' => REQUIREMENT_ERROR,
52 );
53 }
54 else if (!is_readable(GNUPG_HOMEDIR)) {
55 $status['gnupg_homedir'] = array(
56 'title' => t('GnuPG home directory'),
57 'value' => t('Not readable'),
58 'description' => t('The <a href="@gpg">GnuPG</a> home directory %directory is not readable by Drupal. Make sure the <a href="@settings">configuration settings</a> and directory permissions are correct.', array('@gpg' => 'http://www.gnupg.org/', '%directory' => GNUPG_HOMEDIR, '@settings' => url('admin/settings/gnupg'))),
59 'severity' => REQUIREMENT_ERROR,
60 );
61 }
62 }
63 }
64
65 return $status;
66 }
67
68 //////////////////////////////////////////////////////////////////////////////
69 // Schema API hooks
70
71 /**
72 * Implementation of hook_schema().
73 */
74 function gnupg_schema() {
75 return array(
76 'gnupg_keys' => array(
77 'description' => t("Stores users' GnuPG public keys."),
78 'fields' => array(
79 'uri' => array(
80 'description' => t("The URI of the user account associated with the key."),
81 'type' => 'varchar',
82 'length' => 255,
83 'not null' => TRUE,
84 'default' => '',
85 ),
86 'timestamp' => array(
87 'description' => t("The Unix timestamp indicating when the key was stored or last updated."),
88 'type' => 'int',
89 'unsigned' => TRUE,
90 'not null' => TRUE,
91 'default' => 0,
92 ),
93 'key_id' => array(
94 'description' => t("The OpenPGP public key's ID or fingerprint."),
95 'type' => 'varchar',
96 'length' => 64,
97 ),
98 'key_data' => array(
99 'description' => t("The OpenPGP public key in ASCII-armored format."),
100 'type' => 'text',
101 'size' => 'normal',
102 ),
103 ),
104 'primary key' => array('uri'),
105 ),
106 );
107 }
108
109 //////////////////////////////////////////////////////////////////////////////
110 // Schema API updates
111
112 /**
113 * Create the {gnupg_keys} table.
114 *
115 * Added in release 6.x-1.0-beta1.
116 */
117 function gnupg_update_6000() {
118 $updates = array();
119 db_create_table($updates, 'gnupg_keys',
120 array(
121 'description' => t("Stores users' GnuPG public keys."),
122 'fields' => array(
123 'uri' => array(
124 'description' => t("The URI of the user account associated with the key."),
125 'type' => 'varchar',
126 'length' => 255,
127 'not null' => TRUE,
128 'default' => '',
129 ),
130 'timestamp' => array(
131 'description' => t("The Unix timestamp indicating when the key was stored or last updated."),
132 'type' => 'int',
133 'unsigned' => TRUE,
134 'not null' => TRUE,
135 'default' => 0,
136 ),
137 'key_id' => array(
138 'description' => t("The OpenPGP public key's ID or fingerprint."),
139 'type' => 'varchar',
140 'length' => 64,
141 ),
142 'key_data' => array(
143 'description' => t("The OpenPGP public key in ASCII-armored format."),
144 'type' => 'text',
145 'size' => 'normal',
146 ),
147 ),
148 'primary key' => array('uri'),
149 )
150 );
151 return $updates;
152 }
153
154 /**
155 * Store users' public keys in the dedicated {gnupg_keys} table instead of
156 * piggy-backing them in the {users.data} profile information.
157 *
158 * Added in release 6.x-1.0-beta1.
159 */
160 function gnupg_update_6001() {
161 $result = db_query("SELECT uid, data FROM {users} WHERE data LIKE '%gnupg_key%'");
162 while ($user = db_fetch_object($result)) {
163 $data = unserialize($user->data);
164 $key = $data['gnupg_key'];
165 unset($data['gnupg_key']);
166
167 db_query("INSERT INTO {gnupg_keys} (uri, timestamp, key_id, key_data) VALUES ('%s', %d, NULL, '%s')", 'user/' . $user->uid, time(), $key);
168 db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $user->uid);
169 }
170
171 return array();
172 }

  ViewVC Help
Powered by ViewVC 1.1.2