summaryrefslogtreecommitdiff
path: root/modules/image/image.install
blob: d9c6b9a05d061ad177a676b99348bfa8a9d1f657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
// $Id$

/**
 * @file
 * Install, update and uninstall functions for the image module.
 */

/**
 * Implements hook_install().
 */
function image_install() {
  // Create the styles directory and ensure it's writable.
  $directory = file_default_scheme() . '://styles';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}

/**
 * Implements hook_uninstall().
 */
function image_uninstall() {
  // Remove the styles directory and generated images.
  file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
}

/**
 * Implements hook_schema().
 */
function image_schema() {
  $schema = array();

  $schema['cache_image'] = drupal_get_schema_unprocessed('system', 'cache');
  $schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';

  $schema['image_styles'] = array(
    'description' => 'Stores configuration options for image styles.',
    'fields' => array(
      'isid' => array(
        'description' => 'The primary identifier for an image style.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The style name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('isid'),
    'unique keys' => array(
      'name' => array('name'),
    ),
  );

  $schema['image_effects'] = array(
    'description' => 'Stores configuration options for image effects.',
    'fields' => array(
      'ieid' => array(
        'description' => 'The primary identifier for an image effect.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'isid' => array(
        'description' => 'The {image_styles}.isid for an image style.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'description' => 'The weight of the effect in the style.',
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'name' => array(
        'description' => 'The unique name of the effect to be executed.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'data' => array(
        'description' => 'The configuration data for the effect.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array('ieid'),
    'indexes' => array(
      'isid' => array('isid'),
      'weight' => array('weight'),
    ),
    'foreign keys' => array(
      'image_style' => array(
        'table' => 'image_styles',
        'columns' => array('isid' => 'isid'),
      ),
    ),
  );

  return $schema;
}

/**
 * Implements hook_field_schema().
 */
function image_field_schema($field) {
  return array(
    'columns' => array(
      'fid' => array(
        'description' => 'The {file_managed}.fid being referenced in this field.',
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
      'alt' => array(
        'description' => "Alternative image text, for the image's 'alt' attribute.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'title' => array(
        'description' => "Image title text, for the image's 'title' attribute.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
    ),
    'indexes' => array(
      'fid' => array('fid'),
    ),
    'foreign keys' => array(
      'fid' => array(
        'table' => 'file_managed',
        'columns' => array('fid' => 'fid'),
      ),
    ),
  );
}

/**
 * Install the schema for users upgrading from the contributed module.
 */
function image_update_7000() {
  if (!db_table_exists('image_styles')) {
    $schema = array();

    $schema['cache_image'] = system_schema_cache_7054();
    $schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';

    $schema['image_styles'] = array(
      'description' => 'Stores configuration options for image styles.',
      'fields' => array(
        'isid' => array(
          'description' => 'The primary identifier for an image style.',
          'type' => 'serial',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'name' => array(
          'description' => 'The style name.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
        ),
      ),
      'primary key' => array('isid'),
      'unique keys' => array(
        'name' => array('name'),
      ),
    );

    $schema['image_effects'] = array(
      'description' => 'Stores configuration options for image effects.',
      'fields' => array(
        'ieid' => array(
          'description' => 'The primary identifier for an image effect.',
          'type' => 'serial',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'isid' => array(
          'description' => 'The {image_styles}.isid for an image style.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'weight' => array(
          'description' => 'The weight of the effect in the style.',
          'type' => 'int',
          'unsigned' => FALSE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'name' => array(
          'description' => 'The unique name of the effect to be executed.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
        ),
        'data' => array(
          'description' => 'The configuration data for the effect.',
          'type' => 'blob',
          'not null' => TRUE,
          'size' => 'big',
          'serialize' => TRUE,
        ),
      ),
      'primary key' => array('ieid'),
      'indexes' => array(
        'isid' => array('isid'),
        'weight' => array('weight'),
      ),
      'foreign keys' => array(
        'image_style' => array(
          'table' => 'image_styles',
          'columns' => array('isid' => 'isid'),
        ),
      ),
    );

    db_create_table('cache_image', $schema['cache_image']);
    db_create_table('image_styles', $schema['image_styles']);
    db_create_table('image_effects', $schema['image_effects']);
  }
}

/**
 * Rename possibly misnamed {image_effect} table to {image_effects}.
 */
function image_update_7001() {
  // Due to a bug in earlier versions of image_update_7000() it is possible
  // to end up with an {image_effect} table where there should be an
  // {image_effects} table.
  if (!db_table_exists('image_effects') && db_table_exists('image_effect')) {
    db_rename_table('image_effect', 'image_effects');
  }
}

/**
 * Implements hook_requirements() to check the PHP GD Library.
 *
 * @param $phase
 */
function image_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
    // Check for the PHP GD library.
    if (function_exists('imagegd2')) {
      $info = gd_info();
      $requirements['image_gd'] = array(
        'value' => $info['GD Version'],
      );

      // Check for filter and rotate support.
      if (function_exists('imagefilter') && function_exists('imagerotate')) {
        $requirements['image_gd']['severity'] = REQUIREMENT_OK;
      }
      else {
        $requirements['image_gd']['severity'] = REQUIREMENT_ERROR;
        $requirements['image_gd']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="http://www.php.net/manual/book.image.php">the PHP manual</a>.');
      }
    }
    else {
      $requirements['image_gd'] = array(
        'value' => t('Not installed'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('The GD library for PHP is missing or outdated. Check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/book.image.php')),
      );
    }
    $requirements['image_gd']['title'] = t('GD library rotate and desaturate effects');
  }

  return $requirements;
}