Projet

Général

Profil

Paste
Télécharger (6,46 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / flexslider / flexslider.install @ a60304ed

1
<?php
2
/**
3
 * @file
4
 * Installation actions for FlexSlider
5
 */
6

    
7
/**
8
 * Implements hook_schema().
9
 */
10
function flexslider_schema() {
11
  $schema = array();
12

    
13
  $schema['flexslider_optionset'] = array(
14
    'description' => 'Store option sets for flexslider instances.',
15
    'export' => array(
16
      'key' => 'name',
17
      'identifier' => 'preset',
18
      'default hook' => 'flexslider_default_presets',
19
      'api' => array(
20
        'owner' => 'flexslider',
21
        'api' => 'flexslider_default_preset',
22
        'minimum_version' => 1,
23
        'current_version' => 1,
24
      ),
25
    ),
26
    'fields' => array(
27
      'name' => array(
28
        'description' => 'The machine-readable option set name.',
29
        'type' => 'varchar',
30
        'length' => 255,
31
        'not null' => TRUE,
32
      ),
33
      'title' => array(
34
        'description' => 'The human-readable title for this option set.',
35
        'type' => 'varchar',
36
        'length' => 255,
37
        'not null' => TRUE,
38
      ),
39
      'theme' => array(
40
        'description' => 'The flexslider theme.',
41
        'type' => 'varchar',
42
        'length' => 255,
43
        'not null' => TRUE,
44
        'default' => 'classic',
45
      ),
46
      'options' => array(
47
        'description' => 'The options array.',
48
        'type' => 'blob',
49
        'size' => 'big',
50
        'serialize' => TRUE,
51
      ),
52
    ),
53
    'primary key' => array('name'),
54
  );
55

    
56
  return $schema;
57
}
58

    
59
/**
60
 * Implements hook_install().
61
 *
62
 * Adds a 'default' option set for fresh installs.
63
 */
64
function flexslider_install() {
65
  // Do nothing for now
66
}
67

    
68
/**
69
 * Implements hook_uninstall().
70
 */
71
function flexslider_uninstall() {
72
  variable_del('flexslider_debug');
73
  variable_del('flexslider_version');
74
}
75

    
76
/**
77
 * Implements hook_requirements().
78
 */
79
function flexslider_requirements($phase) {
80
  $requirements = array();
81
  // Ensure translations don't break at install time
82
  $t = get_t();
83

    
84
  // Check to see if the flexslider library is available
85
  if ($phase == 'runtime') {
86
    $library = libraries_detect('flexslider');
87

    
88
    if ($library['installed']) {
89
      $version = explode('.', $library['version']);
90

    
91
      if ($version[0] == FLEXSLIDER_COMPATIBLE_MAJOR_VERSION) {
92
        $requirements['flexslider'] = array(
93
          'value' => $library['version'],
94
          'severity' => REQUIREMENT_OK,
95
        );
96
      }
97
      else {
98
        $requirements['flexslider'] = array(
99
          'value' => $library['version'],
100
          'description' => $t('Incompatible version detected. The FlexSlider library version must be from the %version.x branch.', array('%version' => FLEXSLIDER_COMPATIBLE_MAJOR_VERSION)),
101
          'severity' => REQUIREMENT_WARNING,
102
        );
103
      }
104
    }
105
    else {
106
      $requirements['flexslider'] = array(
107
        'value' => $t('FlexSlider library not found.'),
108
        'description' => $t('The FlexSlider library could not be detected. Please consult the README.md for installation instructions.'),
109
        'severity' => REQUIREMENT_ERROR,
110
      );
111
    }
112

    
113
    $requirements['flexslider']['title'] = $t('FlexSlider');
114
  }
115

    
116
  return $requirements;
117
}
118

    
119
/**
120
 * Implements hook_update_N().
121
 *
122
 * Remove/Update table fields to better suit FlexSlider
123
 */
124
function flexslider_update_7001(&$sandbox) {
125
  $field_new = array(
126
    'description' => 'The image style for normal images.',
127
    'type' => 'varchar',
128
    'length' => 255,
129
    'not null' => TRUE,
130
    'default' => 'flexslider_full',
131
  );
132
  // Change the default image style
133
  db_change_field('flexslider_optionset', 'imagestyle_normal', $field_new, array());
134
  // Drop the unused table column
135
  db_drop_field('flexslider_optionset', 'imagestyle_thumb');
136
}
137

    
138
/**
139
 * Implements hook_update_N().
140
 *
141
 * Enables the Image module since it is now explicitly listed as a
142
 * dependency.
143
 */
144
function flexslider_update_7002(&$sandbox) {
145
  module_enable(array('image'));
146
}
147

    
148
/**
149
 * Implements hook_update_N().
150
 *
151
 * Migrate settings from FlexSlider v1 to v2
152
 */
153
function flexslider_update_7200(&$sandbox) {
154
  $t = get_t();
155
  
156
  module_load_include('module', 'flexslider', 'flexslider');
157
  $optionsets = flexslider_optionset_load_all();
158

    
159
  foreach ($optionsets as $optionset) {
160
    // Map old options to new keys/values
161
    $optionset->options['animationSpeed'] = $optionset->options['animationDuration'];
162
    $optionset->options['direction'] = $optionset->options['slidedirection'];
163
    $optionset->options['keyboard'] = $optionset->options['keyboardnav'];
164
    $optionset->options['startAt'] = $optionset->options['slidetostart'];
165
    $optionset->options['start'] = $optionset->options['startCallback'];
166
    $optionset->options['before'] = $optionset->options['beforeCallback'];
167
    $optionset->options['after'] = $optionset->options['afterCallback'];
168
    $optionset->options['end'] = $optionset->options['endCallback'];
169

    
170
    // Delete any options which no longer exist
171
    unset($optionset->options['animationDuration']);
172
    unset($optionset->options['slidedirection']);
173
    unset($optionset->options['keyboardnav']);
174
    unset($optionset->options['startCallback']);
175
    unset($optionset->options['beforeCallback']);
176
    unset($optionset->options['afterCallback']);
177
    unset($optionset->options['endCallback']);
178
    unset($optionset->options['controlsContainer']); // This value changed in the new version. We have to reset it to the default value
179

    
180
    // Merge in defaults for new options
181
    $optionset->options += _flexslider_optionset_defaults();
182

    
183
    // Save the updated optionset
184
    flexslider_optionset_save($optionset);
185
  }
186
  drupal_set_message($t('Optionsets migrated. However it is recommended to go validate all your settings manually. Especially if you have callback functions defined. They may reference functions which no longer exist.'), 'warning');
187
}
188

    
189
function flexslider_update_7201(&$sandbox) {
190
  $field_new = array(
191
    'description' => 'The image style for thumbnail images.',
192
    'type' => 'varchar',
193
    'length' => 255,
194
    'not null' => TRUE,
195
    'default' => 'flexslider_thumbnail',
196
  );
197
  // Change the default image style
198
  db_add_field('flexslider_optionset', 'imagestyle_thumbnail', $field_new, array());
199
}
200

    
201
/**
202
 * Implements hook_update_N().
203
 *
204
 * Remove the image style settings from the optionset
205
 */
206
function flexslider_update_7202(&$sandbox) {
207
  db_drop_field('flexslider_optionset', 'imagestyle_normal');
208
  db_drop_field('flexslider_optionset', 'imagestyle_thumbnail');
209
}
210

    
211
/**
212
 * Implements hook_update_N().
213
 *
214
 * Remove the flexslider_version variable.
215
 */
216
function flexslider_update_7203(&$sandbox) {
217
  variable_del('flexslider_version');
218
}
219

    
220
// @todo add hook_update_N function to migrate old option set data to new values