Projet

Général

Profil

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

root / drupal7 / sites / all / modules / flag / flag.install @ f0456308

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(
125
        'entity_type',
126
        'entity_id',
127
        'uid',
128
        'sid',
129
      ),
130
      'entity_id_fid' => array('entity_id', 'fid'),
131
    ),
132
  );
133

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

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

    
209
  return $schema;
210
}
211

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

    
224
  drupal_set_message(t('Flag has been uninstalled.'));
225
}
226

    
227
/**
228
 * Implements hook_requirements().
229
 */
230
function flag_requirements($phase) {
231
  $requirements = array();
232
  $t = get_t();
233

    
234
  if ($phase == 'runtime') {
235
    if (module_exists('translation') && !module_exists('translation_helpers')) {
236
      $requirements['flag_translation'] = array(
237
        'title' => $t('Flag'),
238
        'severity' => REQUIREMENT_ERROR,
239
        '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.'),
240
        'value' => $t('Translation helpers module not found.'),
241
      );
242
    }
243
    if (module_exists('session_api')) {
244
      if (file_exists('./robots.txt')) {
245
        $flag_path = url('flag') . '/';
246
        // We don't use url() because this may return an absolute URL when
247
        // language negotiation is set to 'domain'.
248
        $flag_path = parse_url($flag_path, PHP_URL_PATH);
249
        $robots_string = 'Disallow: ' . $flag_path;
250
        $contents = file_get_contents('./robots.txt');
251
        if (strpos($contents, $robots_string) === FALSE) {
252
          $requirements['flag_robots'] = array(
253
            'title' => $t('Flag robots.txt problem'),
254
            'severity' => REQUIREMENT_WARNING,
255
            '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)),
256
            'value' => $t('Search engines flagging content'),
257
          );
258
        }
259
      }
260
    }
261
  }
262
  return $requirements;
263
}
264

    
265
function flag_update_last_removed() {
266
  return 6004;
267
}
268

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

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

    
310
  // Add a count index, see http://drupal.org/node/489610.
311
  db_add_index('flag_counts', 'count', array('count'));
312
}
313

    
314
/**
315
 * Add the sid column and unique index on the flag_content table.
316
 */
317
function flag_update_6202() {
318
  // Drop the keys affected by the addition of the SID column.
319
  db_drop_unique_key('flag_content', 'fid_content_id_uid');
320
  db_drop_index('flag_content', 'content_type_uid');
321

    
322
  // Add the column.
323
  db_add_field('flag_content', 'sid', array(
324
    'type' => 'int',
325
    'unsigned' => TRUE,
326
    'not null' => TRUE,
327
    'default' => 0,
328
  ));
329

    
330
  // Re-add the removed keys.
331
  db_add_unique_key('flag_content', 'fid_content_id_uid_sid', array(
332
    'fid',
333
    'content_id',
334
    'uid',
335
    'sid',
336
  ));
337
  db_add_index('flag_content', 'content_type_uid_sid', array(
338
    'content_type',
339
    'uid',
340
    'sid',
341
  ));
342
}
343

    
344
/**
345
 * Remove count = 0 rows from the count tables.
346
 */
347
function flag_update_6203() {
348
  db_delete('flag_counts')
349
    ->condition('count', 0)
350
    ->execute();
351
}
352

    
353
/**
354
 * Remove "content type" from the flag_counts primary key.
355
 */
356
function flag_update_6204() {
357
  db_drop_primary_key('flag_counts');
358
  db_add_primary_key('flag_counts', array('fid', 'content_id'));
359
}
360

    
361
/**
362
 * Provide a better index on the flag_content table including 'uid' and 'sid'.
363
 */
364
function flag_update_6205() {
365
  // This update has been removed and corrected in flag_update_6206.
366
  // See http://drupal.org/node/1105490.
367
}
368

    
369
/**
370
 * Correction to flag_update_6205(). Convert unique key to an index.
371
 */
372
function flag_update_6206() {
373
  // Remove the old index that did not include UID or SID.
374
  if (db_index_exists('flag_content', 'content_type_content_id')) {
375
    db_drop_index('flag_content', 'content_type_content_id');
376
  }
377

    
378
  // Remove the erroneous unique key that was added in flag_update_6205().
379
  if (db_index_exists('flag_content', 'content_type_content_id_uid_sid')) {
380
    db_drop_unique_key('flag_content', 'content_type_content_id_uid_sid');
381
  }
382

    
383
  db_add_index('flag_content', 'content_type_content_id_uid_sid', array(
384
    'content_type',
385
    'content_id',
386
    'uid',
387
    'sid',
388
  ));
389
}
390

    
391
/**
392
 * Adds column last_updated to flag_counts table.
393
 */
394
function flag_update_6207() {
395
  db_add_field('flag_counts', 'last_updated', array(
396
    'type' => 'int',
397
    'unsigned' => TRUE,
398
    'not null' => TRUE,
399
    'default' => 0,
400
    'disp-size' => 11),
401
    array('indexes' => array('last_updated' => array('last_updated'))));
402
}
403

    
404
/**
405
 * Convert flag_count indexes to include FID for more efficient indexing.
406
 */
407
function flag_update_6208() {
408
  db_drop_index('flag_counts', 'count');
409
  db_drop_index('flag_counts', 'last_updated');
410

    
411
  db_add_index('flag_counts', 'fid_count', array('fid', 'count'));
412
  db_add_index('flag_counts', 'fid_last_updated', array('fid', 'last_updated'));
413
}
414

    
415
/**
416
 * Clear caches.
417
 */
418
function flag_update_7201() {
419
  // Do nothing. Update.php is going to clear caches for us.
420
}
421

    
422
/**
423
 * Clean-up flag records for deleted nodes and comments.
424
 */
425
function flag_update_7202() {
426
  // These queries can't use db_delete() because that doesn't support a
427
  // subquery: see http://drupal.org/node/1267508.
428
  // Clean-up for nodes.
429
  db_query("DELETE FROM {flag_content} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
430
  db_query("DELETE FROM {flag_counts} WHERE content_type = 'node' AND NOT EXISTS (SELECT 1 FROM {node} n WHERE content_id = n.nid)");
431
  // Clean-up for comments. Do not use module_exists() because comment module
432
  // could be disabled.
433
  if (db_table_exists('comment')) {
434
    db_query("DELETE FROM {flag_content} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
435
    db_query("DELETE FROM {flag_counts} WHERE content_type = 'comment' AND NOT EXISTS (SELECT 1 FROM {comment} c WHERE content_id = c.cid)");
436
  }
437
}
438

    
439
/**
440
 * Add an index to help with view's flag_handler_relationship when not required.
441
 */
442
function flag_update_7203() {
443
  // Skip if this index was also added by the 6.x-2.x branch.
444
  if (!db_index_exists('flag_content', 'content_id_fid')) {
445
    db_add_index('flag_content', 'content_id_fid', array('content_id', 'fid'));
446
  }
447
}
448

    
449
/**
450
 * Rebuild the class registry due to classes moving files.
451
 */
452
function flag_update_7300() {
453
  registry_rebuild();
454
}
455

    
456
/**
457
 * Rename {flag_content} table to {flagging} and {flags} table to {flag}.
458
 */
459
function flag_update_7301() {
460
  db_rename_table('flag_content', 'flagging');
461
  db_rename_table('flags', 'flag');
462
  // A second cache clear appears to be required here...
463
  cache_clear_all();
464
  // ...which in fact isn't enough, as the schema cache appears to need explicit
465
  // clearing to prevent the next updates failing to get the schema for the new
466
  // table names.
467
  drupal_get_schema(NULL, TRUE);
468
}
469

    
470
/**
471
 * Rename database columns on the {flag} table.
472
 */
473
function flag_update_7302() {
474
  // No keys or indexes are affected.
475
  // Change field 'content_type' to 'entity_type'.
476
  db_change_field('flag', 'content_type', 'entity_type',
477
    // Spec of the field. Identical to our current hook_schema(): we're not
478
    // changing anything except the name.
479
    array(
480
      'description' => 'The flag type, such as one of "node", "comment", or "user".',
481
      'type' => 'varchar',
482
      'length' => '32',
483
      'not null' => TRUE,
484
      'default' => '',
485
    )
486
    // No keys to re-add.
487
  );
488
}
489

    
490
/**
491
 * Rename database columns on the {flagging} table.
492
 */
493
function flag_update_7303() {
494
  // Drop affected keys and indexes.
495
  db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
496
  db_drop_index('flagging', 'content_type_uid_sid');
497
  db_drop_index('flagging', 'content_type_content_id_uid_sid');
498
  db_drop_index('flagging', 'content_id_fid');
499

    
500
  // Change field 'content_type' to 'entity_type'.
501
  db_change_field('flagging', 'content_type', 'entity_type',
502
    // Spec of the field. Identical to our current hook_schema(): we're not
503
    // changing anything except the name.
504
    array(
505
      'description' => 'The flag type, eg "node", "comment", "user".',
506
      'type' => 'varchar',
507
      'length' => '32',
508
      'not null' => TRUE,
509
      'default' => '',
510
    ),
511
    // Keys spec. Some are short-lived, as they are about to be dropped again
512
    // and have hybrid names that refer to 'content_id' still.
513
    array(
514
      'unique keys' => array(
515
        'fid_content_id_uid_sid' => array('fid', 'content_id', 'uid', 'sid'),
516
      ),
517
      'indexes' => array(
518
        'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
519
        'entity_type_content_id_uid_sid' => array(
520
          'entity_type',
521
          'content_id',
522
          'uid',
523
          'sid',
524
        ),
525
        'content_id_fid' => array('content_id', 'fid'),
526
      ),
527
    )
528
  );
529

    
530
  // Now we have to drop keys and indexes all over again!
531
  db_drop_unique_key('flagging', 'fid_content_id_uid_sid');
532
  db_drop_index('flagging', 'entity_type_content_id_uid_sid');
533
  db_drop_index('flagging', 'content_id_fid');
534

    
535
  // Change field 'content_id' to 'entity_id'.
536
  db_change_field('flagging', 'content_id', 'entity_id',
537
    // Spec of the field. Identical to our current hook_schema(): we're not
538
    // changing anything except the name.
539
    array(
540
      'description' => 'The unique ID of the content, such as either the {cid}, {uid}, or {nid}.',
541
      'type' => 'int',
542
      'unsigned' => TRUE,
543
      'not null' => TRUE,
544
      'default' => 0,
545
    ),
546
    // Keys spec. Identical to current hook_schema().
547
    array(
548
      'unique keys' => array(
549
        'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
550
      ),
551
      'indexes' => array(
552
        'entity_type_entity_id_uid_sid' => array(
553
          'entity_type',
554
          'entity_id',
555
          'uid',
556
          'sid',
557
        ),
558
        'entity_id_fid' => array('entity_id', 'fid'),
559
      ),
560
    )
561
  );
562

    
563
  // A serial field must be defined as a key, so make a temporary index on
564
  // 'fcid' so we can safely drop the primary key.
565
  // @see http://drupal.org/node/190027
566
  db_add_index('flagging', 'temp', array('fcid'));
567
  // Drop the primary key so we can rename the field.
568
  db_drop_primary_key('flagging');
569

    
570
  // Change field 'fcid' to 'flagging_id'.
571
  db_change_field('flagging', 'fcid', 'flagging_id',
572
    // Spec of the field. Identical to our current hook_schema(): we're not
573
    // changing anything except the name.
574
    array(
575
      'description' => 'The unique ID for this particular tag.',
576
      'type' => 'serial',
577
      'unsigned' => TRUE,
578
      'not null' => TRUE,
579
    ),
580
    // Keys spec. Identical to current hook_schema().
581
    array(
582
      'primary key' => array('flagging_id'),
583
    )
584
  );
585
  // Drop our temporary index.
586
  db_drop_index('flagging', 'temp');
587

    
588
  cache_clear_all();
589
}
590

    
591
/**
592
 * Rename database columns on the {flag_counts} table.
593
 */
594
function flag_update_7304() {
595
  // Drop keys and indexes using 'content_type'.
596
  db_drop_index('flag_counts', 'fid_content_type');
597
  db_drop_index('flag_counts', 'content_type_content_id');
598

    
599
  // Change field 'content_type' to 'entity_type'.
600
  db_change_field('flag_counts', 'content_type', 'entity_type',
601
    // Spec of the field. Identical to our current hook_schema(): we're not
602
    // changing anything except the name.
603
    array(
604
      'description' => 'The flag type, usually one of "node", "comment", "user".',
605
      'type' => 'varchar',
606
      'length' => '32',
607
      'not null' => TRUE,
608
      'default' => '',
609
    ),
610
    // Keys spec. Some are short-lived, as they are about to be dropped again.
611
    // Note the hybrid names refer to 'content_id' still.
612
    array(
613
      'indexes' => array(
614
        'fid_entity_type' => array('fid', 'entity_type'),
615
        'entity_type_content_id' => array('entity_type', 'content_id'),
616
      ),
617
    )
618
  );
619

    
620
  // Now drop keys and indexes using 'content_id'.
621
  db_drop_primary_key('flag_counts');
622
  db_drop_index('flag_counts', 'entity_type_content_id');
623

    
624
  // Change field 'content_id' to 'entity_id'.
625
  db_change_field('flag_counts', 'content_id', 'entity_id',
626
    // Spec of the field. Identical to our current hook_schema(): we're not
627
    // changing anything except the name.
628
    array(
629
      'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
630
      'type' => 'int',
631
      'unsigned' => TRUE,
632
      'not null' => TRUE,
633
      'default' => 0,
634
      'disp-width' => '10',
635
    ),
636
    // Keys spec. Identical to current hook_schema() now we're finished.
637
    array(
638
      'primary key' => array('fid', 'entity_id'),
639
      'indexes' => array(
640
        'entity_type_entity_id' => array('entity_type', 'entity_id'),
641
      ),
642
    )
643
  );
644
}
645

    
646
/**
647
 * Convert flag roles to permissions.
648
 */
649
function flag_update_7305() {
650
  // We can't use flag_get_flags() to get all flags to act on, because that
651
  // now looks for user permissions and we want the old roles array to convert.
652
  // Hence we need to get flags directly from the database.
653
  // Flags defined in code are saved in the database by flag_get_flags(), so
654
  // this will get them too, unless the module providing them was *only just*
655
  // installed before update.php was run. This edge case is not covered.
656

    
657
  $result = db_query("SELECT name, options FROM {flag}");
658
  $flag_data = $result->fetchAllKeyed();
659

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

    
664
  foreach ($flag_data as $flag_name => $flag_options) {
665
    $flag_options = unserialize($flag_options);
666
    $flag_roles = $flag_options['roles'];
667

    
668
    foreach ($flag_roles['flag'] as $rid) {
669
      $permission = "flag $flag_name";
670
      user_role_grant_permissions($rid, array($permission));
671
    }
672
    foreach ($flag_roles['unflag'] as $rid) {
673
      $permission = "unflag $flag_name";
674
      user_role_grant_permissions($rid, array($permission));
675
    }
676

    
677
    // Save the flag options with the roles array removed.
678
    unset($flag_options['roles']);
679
    db_update('flag')
680
      ->fields(array(
681
        'options' => serialize($flag_options),
682
      ))
683
      ->condition('name', $flag_name)
684
      ->execute();
685
  }
686

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

    
693
  // Direct the user to read the change notice, which has more details of how
694
  // access to flag objects has been affected.
695
  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(
696
    '!url' => 'http://drupal.org/node/1724256',
697
  ));
698
}
699

    
700
/**
701
 * Convert flag view modes settings.
702
 */
703
function flag_update_7306() {
704
  foreach (flag_get_flags() as $flag) {
705
    // Update show_on_teaser property to use new view mode settings.
706
    if (!empty($flag->show_on_teaser)) {
707
      $flag->show_in_links['teaser'] = TRUE;
708
      unset($flag->show_on_teaser);
709
    }
710

    
711
    // Update show_on_page property to use new view mode settings.
712
    if (!empty($flag->show_on_page)) {
713
      $flag->show_in_links['full'] = TRUE;
714
      unset($flag->show_on_page);
715
    }
716

    
717
    // Update show_on_comment and show_on_entity properties to use new view
718
    // mode settings. Since the old logic was to show on all view modes, do
719
    // that.
720
    if (!empty($flag->show_on_entity) || !empty($flag->show_on_comment)) {
721
      if ($entity_info = entity_get_info($flag->entity_type)) {
722
        foreach ($entity_info['view modes'] as $view_mode => $value) {
723
          $flag->show_in_links[$view_mode] = TRUE;
724
        }
725
      }
726

    
727
      unset($flag->show_on_entity, $flag->show_on_comment);
728
    }
729

    
730
    $flag->save();
731
  }
732
}