| 1 |
<?php
|
| 2 |
// $Id: fivestar.install,v 1.7 2009/05/11 04:25:08 quicksketch Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installation file for fivestar module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
function fivestar_schema() {
|
| 10 |
return array();
|
| 11 |
}
|
| 12 |
|
| 13 |
function fivestar_install() {
|
| 14 |
drupal_install_schema('fivestar');
|
| 15 |
if (module_exists('content')) {
|
| 16 |
content_notify('install', 'fivestar');
|
| 17 |
}
|
| 18 |
}
|
| 19 |
|
| 20 |
function fivestar_uninstall() {
|
| 21 |
drupal_uninstall_schema('fivestar');
|
| 22 |
db_query("DELETE FROM {variable} WHERE name LIKE 'fivestar_%'");
|
| 23 |
if (module_exists('content')) {
|
| 24 |
content_notify('uninstall', 'fivestar');
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Implementation of hook_enable().
|
| 30 |
*/
|
| 31 |
function fivestar_enable() {
|
| 32 |
if (module_exists('content')) {
|
| 33 |
module_load_include('inc', 'fivestar', 'fivestar_field');
|
| 34 |
content_notify('enable', 'fivestar');
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_disable().
|
| 40 |
*/
|
| 41 |
function fivestar_disable() {
|
| 42 |
if (module_exists('content')) {
|
| 43 |
content_notify('disable', 'fivestar');
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Function to retrieve the current version to prevent duplicate updates.
|
| 49 |
*/
|
| 50 |
function fivestar_update_version() {
|
| 51 |
static $version;
|
| 52 |
|
| 53 |
if (!isset($version)) {
|
| 54 |
$version = db_result(db_query("SELECT schema_version FROM {system} WHERE type = 'module' AND name = 'fivestar'"));
|
| 55 |
}
|
| 56 |
|
| 57 |
return $version;
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Add the fivestar comment tables.
|
| 62 |
*/
|
| 63 |
function fivestar_update_1() {
|
| 64 |
// No longer needed. The tables are added by fivestar_commment_install().
|
| 65 |
return array();
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Convert previous fivestar widget settings to new format.
|
| 70 |
*/
|
| 71 |
function fivestar_update_2() {
|
| 72 |
$types = node_get_types('names');
|
| 73 |
foreach ($types as $key => $name) {
|
| 74 |
$style = variable_get('fivestar_style_'. $key, 'default');
|
| 75 |
$enabled = variable_get('fivestar_'. $key, FALSE);
|
| 76 |
// Split the display style into two variables for stars and text.
|
| 77 |
if ($enabled) {
|
| 78 |
switch ($style) {
|
| 79 |
case 'default':
|
| 80 |
variable_set('fivestar_style_'. $key, 'user');
|
| 81 |
variable_set('fivestar_text_'. $key, 'average');
|
| 82 |
break;
|
| 83 |
case 'compact':
|
| 84 |
variable_set('fivestar_style_'. $key, 'user');
|
| 85 |
variable_set('fivestar_text_'. $key, 'none');
|
| 86 |
break;
|
| 87 |
case 'dual':
|
| 88 |
variable_set('fivestar_text_'. $key, 'none');
|
| 89 |
break;
|
| 90 |
}
|
| 91 |
}
|
| 92 |
// We no longer save any settings if Fivestar is disabled.
|
| 93 |
else {
|
| 94 |
variable_del('fivestar_unvote_'. $key);
|
| 95 |
variable_del('fivestar_style_'. $key);
|
| 96 |
variable_del('fivestar_position_'. $key);
|
| 97 |
variable_del('fivestar_position_teaser_'. $key);
|
| 98 |
}
|
| 99 |
}
|
| 100 |
return array();
|
| 101 |
}
|
| 102 |
|
| 103 |
/**
|
| 104 |
* Upgrade to Drupal 6 and VotingAPI 2.
|
| 105 |
*
|
| 106 |
* Remove anonymous vote interval from Fivestar, now handled by VotingAPI.
|
| 107 |
*/
|
| 108 |
function fivestar_update_6100() {
|
| 109 |
// If using CCK, make sure it has updated first.
|
| 110 |
if (function_exists('content_check_update') && ($abort = content_check_update('fivestar'))) {
|
| 111 |
return $abort;
|
| 112 |
}
|
| 113 |
|
| 114 |
$ret = array();
|
| 115 |
variable_del('fivestar_anonymous_vote_interval');
|
| 116 |
$ret[] = array('success' => TRUE, 'query' => "variable_del('fivestar_anonymous_vote_interval')");
|
| 117 |
return $ret;
|
| 118 |
}
|
| 119 |
|
| 120 |
/**
|
| 121 |
* Add vote_id column to the fivestar_comment table.
|
| 122 |
*/
|
| 123 |
function fivestar_update_6101() {
|
| 124 |
// Moved to fivestar_commment_update_6100().
|
| 125 |
return array();
|
| 126 |
}
|
| 127 |
|
| 128 |
/**
|
| 129 |
* Set Fivestar weight to -1 so that it can load before content.module.
|
| 130 |
*/
|
| 131 |
function fivestar_update_6102() {
|
| 132 |
$ret = array();
|
| 133 |
|
| 134 |
// This update will already be run as fivestar_update_5701 on Drupal 5.
|
| 135 |
if (fivestar_update_version() >= 6100) {
|
| 136 |
$ret[] = update_sql("UPDATE {system} SET weight = -1 WHERE type = 'module' AND name = 'fivestar'");
|
| 137 |
}
|
| 138 |
return $ret;
|
| 139 |
}
|
| 140 |
|
| 141 |
/**
|
| 142 |
* Move comment support to a separate module.
|
| 143 |
*/
|
| 144 |
function fivestar_update_6103() {
|
| 145 |
// Comment support was added in schema version 1.
|
| 146 |
if (fivestar_update_version() >= 6100) {
|
| 147 |
// Enable the module, but don't run the install hook (tables already exist).
|
| 148 |
if (module_exists('comment')) {
|
| 149 |
module_rebuild_cache();
|
| 150 |
module_enable(array('fivestar_comment'));
|
| 151 |
$version = array_pop(drupal_get_schema_versions('fivestar_comment'));
|
| 152 |
drupal_set_installed_schema_version('fivestar_comment', $version);
|
| 153 |
module_rebuild_cache();
|
| 154 |
}
|
| 155 |
// If the comment table needs an update, run fivestar_comment_update_5100().
|
| 156 |
if (fivestar_update_version() < 6101) {
|
| 157 |
module_load_install('fivestar_comment');
|
| 158 |
fivestar_comment_update_6100();
|
| 159 |
}
|
| 160 |
}
|
| 161 |
return array();
|
| 162 |
}
|
| 163 |
|
| 164 |
/**
|
| 165 |
* Update CCK target logic to rename "target" to "php_target".
|
| 166 |
*/
|
| 167 |
function fivestar_update_6104() {
|
| 168 |
// Previously ran as fivestar_update_5703 on Drupal 5.
|
| 169 |
// Also, don't run this update if CCK is not enabled.
|
| 170 |
if (fivestar_update_version() >= 6100 && module_exists('content')) {
|
| 171 |
$result = db_query("SELECT field_name, global_settings FROM {content_node_field} WHERE type = 'fivestar'");
|
| 172 |
while ($field = db_fetch_object($result)) {
|
| 173 |
$settings = unserialize($field->global_settings);
|
| 174 |
if (!empty($settings['target'])) {
|
| 175 |
if (is_numeric($settings['target'])) {
|
| 176 |
// If previously a straight integer, just add a "return" to the number.
|
| 177 |
$settings['php_target'] = 'return '. $settings['target'];
|
| 178 |
}
|
| 179 |
else {
|
| 180 |
// If already PHP code, remove the PHP brackets.
|
| 181 |
$php = trim($settings['target']);
|
| 182 |
$php = preg_replace('/^<\?(php)?/', '', $php);
|
| 183 |
$php = preg_replace('/\?>$/', '', $php);
|
| 184 |
$settings['php_target'] = $php;
|
| 185 |
}
|
| 186 |
}
|
| 187 |
unset($settings['target']);
|
| 188 |
unset($settings['php']);
|
| 189 |
db_query("UPDATE {content_node_field} SET global_settings = '%s' WHERE field_name = '%s'", serialize($settings), $field->field_name);
|
| 190 |
}
|
| 191 |
}
|
| 192 |
return array();
|
| 193 |
}
|
| 194 |
|
| 195 |
/**
|
| 196 |
* Belated update for Drupal 6: Re-enable Fivestar CCK fields.
|
| 197 |
*/
|
| 198 |
function fivestar_update_6105() {
|
| 199 |
$ret = array();
|
| 200 |
|
| 201 |
if (!module_exists('content')) {
|
| 202 |
$ret[] = array('success' => TRUE, 'query' => t('CCK is not installed. No update ran.'));
|
| 203 |
return $ret;
|
| 204 |
}
|
| 205 |
|
| 206 |
if ($abort = content_check_update('fivestar')) {
|
| 207 |
return $abort;
|
| 208 |
}
|
| 209 |
|
| 210 |
// All CCK fields are disabled by Content module during the D6 upgrade.
|
| 211 |
// Re-enable the Fivestar fields.
|
| 212 |
module_load_include('inc', 'fivestar', 'includes/fivestar.field');
|
| 213 |
content_associate_fields('fivestar');
|
| 214 |
|
| 215 |
$ret[] = array('success' => TRUE, 'query' => t('Re-enabled Fivestar CCK fields.'));
|
| 216 |
|
| 217 |
return $ret;
|
| 218 |
}
|