aggregator.install 9.29 KB
Newer Older
1
2
<?php

3
4
5
6
/**
 * @file
 * Install, update and uninstall functions for the aggregator module.
 */
7
use Drupal\Core\Language\Language;
8

9
10
11
12
13
14
15
/**
 * Implements hook_requirements().
 */
function aggregator_requirements($phase) {
  $has_curl = function_exists('curl_init');
  $requirements = array();
  $requirements['curl'] = array(
16
17
    'title' => t('cURL'),
    'value' => $has_curl ? t('Enabled') : t('Not found'),
18
19
20
  );
  if (!$has_curl) {
    $requirements['curl']['severity'] = REQUIREMENT_ERROR;
21
    $requirements['curl']['description'] = t('The Aggregator module could not be installed because the PHP <a href="@curl_url">cURL</a> library is not available.', array('@curl_url' => 'http://php.net/manual/curl.setup.php'));
22
23
24
25
  }
  return $requirements;
}

26
/**
27
 * Implements hook_schema().
28
29
30
 */
function aggregator_schema() {
  $schema['aggregator_category'] = array(
31
    'description' => 'Stores categories for aggregator feeds and feed items.',
32
    'fields' => array(
33
34
35
      'cid'  => array(
        'type' => 'serial',
        'not null' => TRUE,
36
        'description' => 'Primary Key: Unique aggregator category ID.',
37
38
39
40
41
42
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
43
        'description' => 'Title of the category.',
44
45
46
47
48
      ),
      'description' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
49
        'description' => 'Description of the category',
50
51
52
53
54
55
      ),
      'block' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
56
        'description' => 'The number of recent items to show within the category block.',
57
      )
58
59
    ),
    'primary key' => array('cid'),
60
61
62
    'unique keys' => array(
      'title' => array('title'),
    ),
63
64
65
  );

  $schema['aggregator_category_feed'] = array(
66
    'description' => 'Bridge table; maps feeds to categories.',
67
    'fields' => array(
68
69
70
71
      'fid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
72
        'description' => "The feed's {aggregator_feed}.fid.",
73
74
75
76
77
      ),
      'cid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
78
        'description' => 'The {aggregator_category}.cid to which the feed is being assigned.',
79
      )
80
    ),
81
    'primary key' => array('cid', 'fid'),
82
83
84
    'indexes' => array(
      'fid' => array('fid'),
    ),
85
    'foreign keys' => array(
86
87
88
89
      'aggregator_category' => array(
        'table' => 'aggregator_category',
        'columns' => array('cid' => 'cid'),
      ),
90
    ),
91
92
93
  );

  $schema['aggregator_category_item'] = array(
94
    'description' => 'Bridge table; maps feed items to categories.',
95
    'fields' => array(
96
97
98
99
      'iid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
100
        'description' => "The feed item's {aggregator_item}.iid.",
101
102
103
104
105
      ),
      'cid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
106
        'description' => 'The {aggregator_category}.cid to which the feed item is being assigned.',
107
      )
108
    ),
109
    'primary key' => array('cid', 'iid'),
110
111
112
    'indexes' => array(
      'iid' => array('iid'),
    ),
113
    'foreign keys' => array(
114
115
116
117
      'aggregator_category' => array(
        'table' => 'aggregator_category',
        'columns' => array('cid' => 'cid'),
      ),
118
    ),
119
120
121
  );

  $schema['aggregator_feed'] = array(
122
    'description' => 'Stores feeds to be parsed by the aggregator.',
123
    'fields' => array(
124
125
126
      'fid' => array(
        'type' => 'serial',
        'not null' => TRUE,
127
        'description' => 'Primary Key: Unique feed ID.',
128
129
130
131
132
133
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
134
        'description' => 'Title of the feed.',
135
      ),
136
137
138
139
140
141
142
      'langcode' => array(
        'description' => 'The {language}.langcode of this feed.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
143
      'url' => array(
144
        'type' => 'text',
145
        'not null' => TRUE,
146
        'description' => 'URL to the feed.',
147
148
149
150
151
      ),
      'refresh' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
152
        'description' => 'How often to check for new feed items, in seconds.',
153
154
155
156
157
      ),
      'checked' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
158
        'description' => 'Last time feed was checked for new items, as Unix timestamp.',
159
      ),
160
161
162
163
164
165
      'queued' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Time when this feed was queued for refresh, 0 if not queued.',
      ),
166
      'link' => array(
167
        'type' => 'text',
168
        'not null' => TRUE,
169
        'description' => 'The parent website of the feed; comes from the <link> element in the feed.',
170
171
172
173
174
      ),
      'description' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
175
        'description' => "The parent website's description; comes from the <description> element in the feed.",
176
177
178
179
180
      ),
      'image' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
181
        'description' => 'An image representing the feed.',
182
      ),
183
184
      'hash' => array(
        'type' => 'varchar',
185
        'length' => 64,
186
187
        'not null' => TRUE,
        'default' => '',
188
        'description' => 'Calculated hash of the feed data, used for validating cache.',
189
      ),
190
191
192
193
194
      'etag' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
195
        'description' => 'Entity tag HTTP response header, used for validating cache.',
196
197
198
199
200
      ),
      'modified' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
201
        'description' => 'When the feed was last modified, as a Unix timestamp.',
202
      ),
203
    ),
204
    'primary key' => array('fid'),
205
    'indexes' => array(
206
      'url'  => array(array('url', 255)),
207
208
      'queued' => array('queued'),
    ),
209
210
211
    'unique keys' => array(
      'title' => array('title'),
    ),
212
213
214
  );

  $schema['aggregator_item'] = array(
215
    'description' => 'Stores the individual items imported from feeds.',
216
    'fields' => array(
217
218
219
      'iid'  => array(
        'type' => 'serial',
        'not null' => TRUE,
220
        'description' => 'Primary Key: Unique ID for feed item.',
221
222
223
224
225
      ),
      'fid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
226
        'description' => 'The {aggregator_feed}.fid to which this item belongs.',
227
228
      ),
      'title' => array(
Dries's avatar
Dries committed
229
230
        'type' => 'varchar',
        'length' => 255,
231
        'not null' => TRUE,
Dries's avatar
Dries committed
232
        'default' => '',
233
        'description' => 'Title of the feed item.',
234
      ),
235
236
237
238
239
240
241
      'langcode' => array(
        'description' => 'The {language}.langcode of this feed item.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
242
      'link' => array(
243
        'type' => 'text',
244
        'not null' => TRUE,
245
        'description' => 'Link to the feed item.',
246
247
248
249
250
251
      ),
      'author' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
252
        'description' => 'Author of the feed item.',
253
254
255
256
257
      ),
      'description' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
258
        'description' => 'Body of the feed item.',
259
260
261
262
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => FALSE,
263
        'description' => 'Posted date of the feed item, as a Unix timestamp.',
264
265
      ),
      'guid' => array(
266
267
        'type' => 'text',
        'not null' => TRUE,
268
        'description' => 'Unique identifier for the feed item.',
269
      )
270
271
    ),
    'primary key' => array('iid'),
272
273
274
    'indexes' => array(
      'fid' => array('fid'),
    ),
275
    'foreign keys' => array(
276
277
278
279
      'aggregator_feed' => array(
        'table' => 'aggregator_feed',
        'columns' => array('fid' => 'fid'),
      ),
280
    ),
281
282
283
284
  );

  return $schema;
}
285
286
287
288
289
290

/**
 * Moves aggregator settings from variables to config.
 *
 * @ingroup config_upgrade
 */
291
function aggregator_update_8000() {
292
293
294
295
296
297
298
299
300
301
302
  update_variables_to_config('aggregator.settings', array(
    'aggregator_fetcher' => 'fetcher',
    'aggregator_parser' => 'parser',
    'aggregator_processors' => 'processors',
    'aggregator_allowed_html_tags' => 'items.allowed_html',
    'aggregator_teaser_length' => 'items.teaser_length',
    'aggregator_clear' => 'items.expire',
    'aggregator_summary_items' => 'source.list_max',
    'aggregator_category_selector' => 'source.category_selector',
  ));
}
303
304
305
306
307
308
309
310
311
312
313
314

/**
 * Adds the langcode field to {aggregator_item} and {aggregator_feed}.
 */
function aggregator_update_8001() {
  // Add the field.
  db_add_field('aggregator_feed', 'langcode', array(
    'description' => 'The {language}.langcode of this feed.',
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
315
    'initial' => Language::LANGCODE_DEFAULT,
316
317
318
319
320
321
322
  ));
  db_add_field('aggregator_item', 'langcode', array(
    'description' => 'The {language}.langcode of this feed item.',
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
323
    'initial' => Language::LANGCODE_DEFAULT,
324
325
  ));
}