Projet

Général

Profil

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

root / htmltest / sites / all / modules / flag / flag.install @ a5572547

1
<?php
2

    
3
/**
4
 * @file
5
 * Flag module install/schema/update hooks.
6
 */
7

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

    
14
  $schema['flag'] = array(
15
    'description' => 'All available flags in the system.',
16
    'fields' => array(
17
      'fid' => array(
18
        'description' => 'The unique ID for this particular flag.',
19
        'type' => 'serial',
20
        'size' => 'small',
21
        'unsigned' => TRUE,
22
        'not null' => TRUE,
23
      ),
24
      'entity_type' => array(
25
        'description' => 'The flag type, such as one of "node", "comment", or "user".',
26
        'type' => 'varchar',
27
        'length' => '128',
28
        'not null' => TRUE,
29
        'default' => '',
30
      ),
31
      'name' => array(
32
        'description' => 'The machine-name for this flag.',
33
        'type' => 'varchar',
34
        'length' => '32',
35
        'not null' => FALSE,
36
        'default' => '',
37
      ),
38
      'title' => array(
39
        'description' => 'The human-readable title for this flag.',
40
        'type' => 'varchar',
41
        'length' => '255',
42
        'not null' => FALSE,
43
        'default' => '',
44
      ),
45
      'global' => array(
46
        'description' => 'Whether this flag state should act as a single toggle to all users across the site.',
47
        'type' => 'int',
48
        'size' => 'tiny',
49
        'not null' => FALSE,
50
        'default' => 0,
51
      ),
52
      'options' => array(
53
        'description' => 'The options and configuration of this flag.',
54
        'type' => 'text',
55
        'not null' => FALSE,
56
      ),
57
    ),
58
    'primary key' => array('fid'),
59
    'unique keys' => array(
60
      'name' => array('name'),
61
    ),
62
  );
63

    
64
  $schema['flagging'] = array(
65
    'description' => 'Objects that have been flagged.',
66
    'fields' => array(
67
      'flagging_id' => array(
68
        'description' => 'The unique ID for this particular tag.',
69
        'type' => 'serial',
70
        'unsigned' => TRUE,
71
        'not null' => TRUE,
72
      ),
73
      'fid' => array(
74
        'description' => 'The unique flag ID this object has been flagged with, from {flag}.',
75
        'type' => 'int',
76
        'size' => 'small',
77
        'unsigned' => TRUE,
78
        'not null' => TRUE,
79
        'default' => 0,
80
      ),
81
      'entity_type' => array(
82
        'description' => 'The flag type, eg "node", "comment", "user".',
83
        'type' => 'varchar',
84
        'length' => '128',
85
        'not null' => TRUE,
86
        'default' => '',
87
      ),
88
      'entity_id' => array(
89
        'description' => 'The unique ID of the object, such as either the {cid}, {uid}, or {nid}.',
90
        'type' => 'int',
91
        'unsigned' => TRUE,
92
        'not null' => TRUE,
93
        'default' => 0,
94
      ),
95
      'uid' => array(
96
        'description' => 'The user ID by whom this object was flagged.',
97
        'type' => 'int',
98
        'unsigned' => TRUE,
99
        'not null' => TRUE,
100
        'default' => 0,
101
      ),
102
      'sid' => array(
103
        'description' => "The user's numeric sid from the session_api table.",
104
        'type' => 'int',
105
        'unsigned' => TRUE,
106
        'not null' => TRUE,
107
        'default' => 0,
108
      ),
109
      'timestamp' => array(
110
        'description' => 'The UNIX time stamp representing when the flag was set.',
111
        'type' => 'int',
112
        'unsigned' => TRUE,
113
        'not null' => TRUE,
114
        'default' => 0,
115
        'disp-size' => 11,
116
      )
117
    ),
118
    'primary key' => array('flagging_id'),
119
    'unique keys' => array(
120
      'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
121
    ),
122
    'indexes' => array(
123
      'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
124
      'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
125
      'entity_id_fid' => array('entity_id', 'fid'),
126
    ),
127
  );
128

    
129
  $schema['flag_types'] = array(
130
    'description' => 'The entity bundles that are affected by a flag.',
131
    'fields' => array(
132
      'fid' => array(
133
        'description' => 'The unqiue flag ID as defined for the flag in {flag}.',
134
        'type' => 'int',
135
        'size' => 'small',
136
        'unsigned' => TRUE,
137
        'not null' => TRUE,
138
        'default' => 0,
139
      ),
140
      'type' => array(
141
        'description' => 'The entity bundles that can be flagged by this fid.',
142
        'type' => 'varchar',
143
        'length' => '128',
144
        'not null' => TRUE,
145
        'default' => '',
146
      ),
147
    ),
148
    'indexes' => array(
149
      'fid' => array('fid'),
150
    ),
151
  );
152

    
153
  $schema['flag_counts'] = array(
154
    'description' => 'The number of times an item has been flagged.',
155
    'fields' => array(
156
      'fid' => array(
157
        'type' => 'int',
158
        'size' => 'small',
159
        'unsigned' => TRUE,
160
        'not null' => TRUE,
161
        'default' => 0,
162
      ),
163
      'entity_type' => array(
164
        'description' => 'The flag type, usually one of "node", "comment", "user".',
165
        'type' => 'varchar',
166
        'length' => '128',
167
        'not null' => TRUE,
168
        'default' => '',
169
      ),
170
      'entity_id' => array(
171
        'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
172
        'type' => 'int',
173
        'unsigned' => TRUE,
174
        'not null' => TRUE,
175
        'default' => 0,
176
        'disp-width' => '10',
177
      ),
178
      'count' => array(
179
        'description' => 'The number of times this object has been flagged for this flag.',
180
        'type' => 'int',
181
        'unsigned' => TRUE,
182
        'not null' => TRUE,
183
        'default' => 0,
184
        'disp-width' => '10',
185
      ),
186
      'last_updated' => array(
187
        'description' => 'The UNIX time stamp representing when the flag was last updated.',
188
        'type' => 'int',
189
        'unsigned' => TRUE,
190
        'not null' => TRUE,
191
        'default' => 0,
192
        'disp-size' => 11,
193
      )
194
    ),
195
    'primary key' => array('fid', 'entity_id'),
196
    'indexes' => array(
197
      'fid_entity_type' => array('fid', 'entity_type'),
198
      'entity_type_entity_id' => array('entity_type', 'entity_id'),
199
      'fid_count' => array('fid', 'count'),
200
      'fid_last_updated' => array('fid', 'last_updated'),
201
    ),
202
  );
203

    
204
  return $schema;
205
}
206

    
207
/**
208
 * Implements hook_uninstall().
209
 */
210
function flag_uninstall() {
211
  $result = db_select('variable', 'v')
212
    ->fields('v', array('name'))
213
    ->condition('name', 'flag_%', 'LIKE')
214
    ->execute();
215
  foreach ($result as $row) {
216
    variable_del($row->name);
217
  }
218

    
219
  drupal_set_message(t('Flag has been uninstalled.'));
220
}
221

    
222
/**
223
 * Implements hook_requirements().
224
 */
225
function flag_requirements($phase) {
226
  $requirements = array();
227
  $t = get_t();
228

    
229
  if ($phase == 'runtime') {
230
    if (module_exists('translation') && !module_exists('translation_helpers')) {
231
      $requirements['flag_translation'] = array(
232
        'title' => $t('Flag'),
233
        'severity' => REQUIREMENT_ERROR,
234
        'description' => $t('To have the flag module work with translations, you need to install and enable the <a href="http://drupal.org/project/translation_helpers">Translation helpers</a> module.'),
235
        'value' => $t('Translation helpers module not found.'),
236
      );
237
    }
238
    if (module_exists('session_api')) {
239
      if (file_exists('./robots.txt')) {
240
        $flag_path = url('flag') . '/';
241
        // We don't use url() because this may return an absolute URL when
242
        // language negotiation is set to 'domain'.
243
        $flag_path = parse_url($flag_path, PHP_URL_PATH);
244
        $robots_string = 'Disallow: ' . $flag_path;
245
        $contents = file_get_contents('./robots.txt');
246
        if (strpos($contents, $robots_string) === FALSE) {
247
          $requirements['flag_robots'] = array(
248
            'title' => $t('Flag robots.txt problem'),
249
            'severity' => REQUIREMENT_WARNING,
250
            'description' => $t('Flag module may currently be used with anonymous users, however the robots.txt file does not exclude the "@flag-path" path, which may cause search engines to randomly flag and unflag content when they index the site. It is highly recommended to add "@robots-string" to your robots.txt file (located in the root of your Drupal installation).', array('@flag-path' => $flag_path, '@robots-string' => $robots_string)),
251
            'value' => $t('Search engines flagging content'),
252
          );
253
        }
254
      }
255
    }
256
  }
257
  return $requirements;
258
}
259

    
260
function flag_update_last_removed() {
261
  return 6004;
262
}
263

    
264
/**
265
 * Convert role access to have separate "flag" and "unflag" permissions.
266
 */
267
function flag_update_6200() {
268
  if (db_field_exists('flags', 'roles')) {
269
    $result = db_select('flags', 'f')
270
      ->fields('f')
271
      ->execute();
272
    foreach ($result as $flag) {
273
      $roles = array_filter(explode(',', $flag->roles));
274
      $options = unserialize($flag->options);
275
      $options['roles'] = array(
276
        'flag' => $roles,
277
        'unflag' => $roles,
278
      );
279
      db_update('flags')
280
        ->fields(array(
281
          'options' => serialize($options),
282
        ))
283
        ->condition('fid', $flag->fid)
284
        ->execute();
285
    }
286
    db_drop_field('flags', 'roles');
287
  }
288
}
289

    
290
/**
291
 * Refine the indexes.
292
 *
293
 * The content type inclusion actually slowed down on unique key. And a count
294
 * index would be helpful for sorting by counts.
295
 */
296
function flag_update_6201() {
297
  // Remove "content type" from one key, see http://drupal.org/node/612602.
298
  db_drop_unique_key('flag_content', 'fid_content_type_content_id_uid');
299
  db_add_unique_key('flag_content', 'fid_content_id_uid', array('fid', 'content_id', 'uid'));
300

    
301
  // Add a count index, see http://drupal.org/node/489610.
302
  db_add_index('flag_counts', 'count', array('count'));
303
}
304

    
305
/**
306
 * Add the sid column and unique index on the flag_content table.
307
 */
308
function flag_update_6202() {
309
  // Drop the keys affected by the addition of the SID column.
310
  db_drop_unique_key('flag_content', 'fid_content_id_uid');
311
  db_drop_index('flag_content', 'content_type_uid');
312

    
313
  // Add the column.
314
  db_add_field('flag_content', 'sid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
315

    
316
  // Re-add the removed keys.
317
  db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array('fid', 'content_id', 'uid', 'sid'));
318
  db_add_index('flag_content', 'content_type_uid_sid', array('content_type', 'uid', 'sid'));
319
}
320

    
321
/**
322
 * Remove count = 0 rows from the count tables.
323
 */
324
function flag_update_6203() {
325
  db_delete('flag_counts')
326
    ->condition('count', 0)
327
    ->execute();
328
}
329

    
330
/**
331
 * Remove "content type" from the flag_counts primary key.
332
 */
333
function flag_update_6204() {
334
  db_drop_primary_key('flag_counts');
335
  db_add_primary_key('flag_counts', array('fid', 'content_id'));
336
}
337

    
338
/**
339
 * Provide a better index on the flag_content table including 'uid' and 'sid'.
340
 */
341
function flag_update_6205() {
342
  // This update has been removed and corrected in flag_update_6206.
343
  // See http://drupal.org/node/1105490.
344
}
345

    
346
/**
347
 * Correction to flag_update_6205(). Convert unique key to an index.
348
 */
349
function flag_update_6206() {
350
  // Remove the old index that did not include UID or SID.
351
  if (db_index_exists('flag_content', 'content_type_content_id')) {
352
    db_drop_index('flag_content', 'content_type_content_id');
353
  }
354

    
355
  // Remove the erroneous unique key that was added in flag_update_6205().
356
  if (db_index_exists('flag_content', 'content_type_content_id_uid_sid')) {
357
    db_drop_unique_key('flag_content', 'content_type_content_id_uid_sid');
358
  }
359

    
360
  db_add_index('flag_content', 'content_type_content_id_uid_sid', array('content_type', 'content_id', 'uid', 'sid'));
361
}
362

    
363
/**
364
 * Adds column last_updated to flag_counts table.
365
 */
366
function flag_update_6207() {
367
  db_add_field('flag_counts', 'last_updated', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-size' => 11), array('indexes' => array('last_updated' => array('last_updated'))));
368
}
369

    
370
/**
371
 * Convert flag_count indexes to include FID for more efficient indexing.
372
 */
373
function flag_update_6208() {
374
  db_drop_index('flag_counts', 'count');
375
  db_drop_index('flag_counts', 'last_updated');
376

    
377
  db_add_index('flag_counts', 'fid_count', array('fid', 'count'));
378
  db_add_index('flag_counts', 'fid_last_updated', array('fid', 'last_updated'));
379
}
380

    
381
/**
382
 * Clear caches.
383
 */
384
function flag_update_7201() {
385
  // Do nothing. Update.php is going to clear caches for us.
386
}
387

    
388
/**
389
 * Clean-up flag records for deleted nodes and comments.
390
 */
391
function flag_update_7202() {
392
  // These queries can't use db_delete() because that doesn't support a
393
  // subquery: see http://drupal.org/node/1267508.
394
  // Clean-up for nodes.
395
  db_query("DELETE FROM {flag_content} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
396
  db_query("DELETE FROM {flag_counts} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
397
  // Clean-up for comments. Do not use module_exists() because comment module
398
  // could be disabled.
399
  if (db_table_exists('comment')) {
400
    db_query("DELETE FROM {flag_content} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
401
    db_query("DELETE FROM {flag_counts} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
402
  }
403
}
404

    
405
/**
406
 * Add an index to help with view's flag_handler_relationship when not required.
407
 */
408
function flag_update_7203() {
409
  // Skip if this index was also added by the 6.x-2.x branch.
410
  if (!db_index_exists('flag_content', 'content_id_fid')) {
411
    db_add_index('flag_content', 'content_id_fid', array('content_id', 'fid'));
412
  }
413
}
414

    
415
/**
416
 * Rebuild the class registry due to classes moving files.
417
 */
418
function flag_update_7300() {
419
  registry_rebuild();
420
}
421

    
422
/**
423
 * Rename {flag_content} table to {flagging} and {flags} table to {flag}.
424
 */
425
function flag_update_7301() {
426
  db_rename_table('flag_content', 'flagging');
427
  db_rename_table('flags', 'flag');
428
  // A second cache clear appears to be required here...
429
  cache_clear_all();
430
  // ...which in fact isn't enough, as the schema cache appears to need explicit
431
  // clearing to prevent the next updates failing to get the schema for the new
432
  // table names.
433
  drupal_get_schema(NULL, TRUE);
434
}
435

    
436
/**
437
 * Rename database columns on the {flag} table.
438
 */
439
function flag_update_7302() {
440
  // No keys or indexes are affected.
441
  // Change field 'content_type' to 'entity_type'.
442
  db_change_field('flag', 'content_type', 'entity_type',
443
    // Spec of the field. Identical to our current hook_schema(): we're not
444
    // changing anything except the name.
445
    array(
446
      'description' => 'The flag type, such as one of "node", "comment", or "user".',
447
      'type' => 'varchar',
448
      'length' => '32',
449
      'not null' => TRUE,
450
      'default' => '',
451
    )
452
    // No keys to re-add.
453
  );
454
}
455

    
456
/**
457
 * Rename database columns on the {flagging} table.
458
 */
459
function flag_update_7303() {
460
  // Drop affected keys and indexes.
461
  db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
462
  db_drop_index('flagging', 'content_type_uid_sid');
463
  db_drop_index('flagging', 'content_type_content_id_uid_sid');
464
  db_drop_index('flagging', 'content_id_fid');
465

    
466
  // Change field 'content_type' to 'entity_type'.
467
  db_change_field('flagging', 'content_type', 'entity_type',
468
    // Spec of the field. Identical to our current hook_schema(): we're not
469
    // changing anything except the name.
470
    array(
471
      'description' => 'The flag type, eg "node", "comment", "user".',
472
      'type' => 'varchar',
473
      'length' => '32',
474
      'not null' => TRUE,
475
      'default' => '',
476
    ),
477
    // Keys spec. Some are short-lived, as they are about to be dropped again
478
    // and have hybrid names that refer to 'content_id' still.
479
    array(
480
      'unique keys' => array(
481
        'fid_content_id_uid_sid' => array('fid', 'content_id', 'uid', 'sid'),
482
      ),
483
      'indexes' => array(
484
        'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
485
        'entity_type_content_id_uid_sid' => array('entity_type', 'content_id', 'uid', 'sid'),
486
        'content_id_fid' => array('content_id', 'fid'),
487
      ),
488
    )
489
  );
490

    
491
  // Now we have to drop keys and indexes all over again!
492
  db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
493
  db_drop_index('flagging', 'entity_type_content_id_uid_sid');
494
  db_drop_index('flagging', 'content_id_fid');
495

    
496
  // Change field 'content_id' to 'entity_id'.
497
  db_change_field('flagging', 'content_id', 'entity_id',
498
    // Spec of the field. Identical to our current hook_schema(): we're not
499
    // changing anything except the name.
500
    array(
501
      'description' => 'The unique ID of the content, such as either the {cid}, {uid}, or {nid}.',
502
      'type' => 'int',
503
      'unsigned' => TRUE,
504
      'not null' => TRUE,
505
      'default' => 0,
506
    ),
507
    // Keys spec. Identical to current hook_schema().
508
    array(
509
      'unique keys' => array(
510
        'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
511
      ),
512
      'indexes' => array(
513
        'entity_type_entity_id_uid_sid' => array('entity_type', 'entity_id', 'uid', 'sid'),
514
        'entity_id_fid' => array('entity_id', 'fid'),
515
      ),
516
    )
517
  );
518

    
519
  // A serial field must be defined as a key, so make a temporary index on
520
  // 'fcid' so we can safely drop the primary key.
521
  // @see http://drupal.org/node/190027
522
  db_add_index('flagging', 'temp', array('fcid'));
523
  // Drop the primary key so we can rename the field.
524
  db_drop_primary_key('flagging');
525

    
526
  // Change field 'fcid' to 'flagging_id'.
527
  db_change_field('flagging', 'fcid', 'flagging_id',
528
    // Spec of the field. Identical to our current hook_schema(): we're not
529
    // changing anything except the name.
530
    array(
531
      'description' => 'The unique ID for this particular tag.',
532
      'type' => 'serial',
533
      'unsigned' => TRUE,
534
      'not null' => TRUE,
535
    ),
536
    // Keys spec. Identical to current hook_schema().
537
    array(
538
      'primary key' => array('flagging_id'),
539
    )
540
  );
541
  // Drop our temporary index.
542
  db_drop_index('flagging', 'temp');
543

    
544
  cache_clear_all();
545
}
546

    
547
/**
548
 * Rename database columns on the {flag_counts} table.
549
 */
550
function flag_update_7304() {
551
  // Drop keys and indexes using 'content_type'.
552
  db_drop_index('flag_counts', 'fid_content_type');
553
  db_drop_index('flag_counts', 'content_type_content_id');
554

    
555
  // Change field 'content_type' to 'entity_type'.
556
  db_change_field('flag_counts', 'content_type', 'entity_type',
557
    // Spec of the field. Identical to our current hook_schema(): we're not
558
    // changing anything except the name.
559
    array(
560
      'description' => 'The flag type, usually one of "node", "comment", "user".',
561
      'type' => 'varchar',
562
      'length' => '32',
563
      'not null' => TRUE,
564
      'default' => '',
565
    ),
566
    // Keys spec. Some are short-lived, as they are about to be dropped again.
567
    // Note the hybrid names refer to 'content_id' still.
568
    array(
569
      'indexes' => array(
570
        'fid_entity_type' => array('fid', 'entity_type'),
571
        'entity_type_content_id' => array('entity_type', 'content_id'),
572
      )
573
    )
574
  );
575

    
576
  // Now drop keys and indexes using 'content_id'.
577
  db_drop_primary_key('flag_counts');
578
  db_drop_index('flag_counts', 'entity_type_content_id');
579

    
580
  // Change field 'content_id' to 'entity_id'.
581
  db_change_field('flag_counts', 'content_id', 'entity_id',
582
    // Spec of the field. Identical to our current hook_schema(): we're not
583
    // changing anything except the name.
584
    array(
585
      'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
586
      'type' => 'int',
587
      'unsigned' => TRUE,
588
      'not null' => TRUE,
589
      'default' => 0,
590
      'disp-width' => '10',
591
    ),
592
    // Keys spec. Identical to current hook_schema() now we're finished.
593
    array(
594
      'primary key' => array('fid', 'entity_id'),
595
      'indexes' => array(
596
        'entity_type_entity_id' => array('entity_type', 'entity_id'),
597
      ),
598
    )
599
  );
600
}
601

    
602
/**
603
 * Convert flag roles to permissions.
604
 */
605
function flag_update_7305() {
606
  // We can't use flag_get_flags() to get all flags to act on, because that
607
  // now looks for user permissions and we want the old roles array to convert.
608
  // Hence we need to get flags directly from the database.
609
  // Flags defined in code are saved in the database by flag_get_flags(), so
610
  // this will get them too, unless the module providing them was *only just*
611
  // installed before update.php was run. This edge case is not covered.
612

    
613
  $result = db_query("SELECT name, options FROM {flag}");
614
  $flag_data = $result->fetchAllKeyed();
615

    
616
  // Note we don't call hook_flag_alter() because we don't have a complete flag.
617
  // If your custom module does something to flag roles, it is your
618
  // responsibility to handle upgrading your extra role data.
619

    
620
  foreach ($flag_data as $flag_name => $flag_options) {
621
    $flag_options = unserialize($flag_options);
622
    $flag_roles = $flag_options['roles'];
623

    
624
    foreach ($flag_roles['flag'] as $rid) {
625
      $permission = "flag $flag_name";
626
      user_role_grant_permissions($rid, array($permission));
627
    }
628
    foreach ($flag_roles['unflag'] as $rid) {
629
      $permission = "unflag $flag_name";
630
      user_role_grant_permissions($rid, array($permission));
631
    }
632

    
633
    // Save the flag options with the roles array removed.
634
    unset($flag_options['roles']);
635
    db_update('flag')
636
      ->fields(array(
637
        'options' => serialize($flag_options),
638
      ))
639
      ->condition('name', $flag_name)
640
      ->execute();
641
  }
642

    
643
  // Flags in code will now report as overridden because the roles option is no
644
  // longer output. Notify the user that they should update them.
645
  if (count(module_implements('flag_default_flags'))) {
646
    drupal_set_message(t('Flags which are defined in code with hook_flag_default_flags() or Features need to be re-exported.'));
647
  }
648

    
649
  // Direct the user to read the change notice, which has more details of how
650
  // access to flag objects has been affected.
651
  return t('Flag roles have been converted to user permissions. Permissions have been granted to each flag based on flag roles. You should review the consequences of this in the <a href="!url">change record</a>.', array(
652
    '!url' => 'http://drupal.org/node/1724256',
653
  ));
654
}
655

    
656
/**
657
 * Convert flag view modes settings.
658
 */
659
function flag_update_7306() {
660
  foreach (flag_get_flags() as $flag) {
661
    // Update show_on_teaser property to use new view mode settings.
662
    if (!empty($flag->show_on_teaser)) {
663
      $flag->show_in_links['teaser'] = TRUE;
664
      unset($flag->show_on_teaser);
665
    }
666

    
667
    // Update show_on_page property to use new view mode settings.
668
    if (!empty($flag->show_on_page)) {
669
      $flag->show_in_links['full'] = TRUE;
670
      unset($flag->show_on_page);
671
    }
672

    
673
    // Update show_on_comment and show_on_entity properties to use new view
674
    // mode settings. Since the old logic was to show on all view modes, do that.
675
    if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
676
      if ($entity_info = entity_get_info($flag->entity_type)) {
677
        foreach ($entity_info['view modes'] as $view_mode => $value) {
678
          $flag->show_in_links[$view_mode] = TRUE;
679
        }
680
      }
681

    
682
      unset($flag->show_on_entity, $flag->show_on_comment);
683
    }
684

    
685
    $flag->save();
686
  }
687
}