Révision a1cafe7e
Ajouté par Assos Assos il y a plus de 4 ans
drupal7/sites/all/modules/field_collection/field_collection.install | ||
---|---|---|
63 | 63 |
), |
64 | 64 |
), |
65 | 65 |
); |
66 |
|
|
67 |
if (module_exists('entitycache')) { |
|
68 |
$schema['cache_entity_field_collection_item'] = drupal_get_schema_unprocessed('system', 'cache'); |
|
69 |
$schema['cache_entity_field_collection_item']['description'] = 'Cache table used to store field_collection_item entity records.'; |
|
70 |
} |
|
71 |
|
|
66 | 72 |
return $schema; |
67 | 73 |
} |
68 | 74 |
|
... | ... | |
228 | 234 |
->condition('archived', 0); |
229 | 235 |
$select->leftJoin('field_data_' . $field_name, 'field', "field.{$field_name}_value = fci.item_id "); |
230 | 236 |
$select->isNull('field.entity_id'); |
231 |
$ids = $select->execute()->fetchCol(0);
|
|
237 |
$ids = $select->execute()->fetchCol(); |
|
232 | 238 |
|
233 | 239 |
entity_delete_multiple('field_collection_item', $ids); |
234 | 240 |
drupal_set_message(t('Deleted @count orphaned field collection items.', array('@count' => count($ids)))); |
... | ... | |
368 | 374 |
->fieldLanguageCondition($f_name, LANGUAGE_NONE); |
369 | 375 |
$query_result = $query->execute(); |
370 | 376 |
if (isset($query_result['field_collection_item'])) { |
371 |
$results = $results + $query_result['field_collection_item'];
|
|
377 |
$results += $query_result['field_collection_item'];
|
|
372 | 378 |
} |
373 | 379 |
} |
374 | 380 |
} |
... | ... | |
393 | 399 |
} |
394 | 400 |
} |
395 | 401 |
} |
402 |
|
|
403 |
/** |
|
404 |
* Update revisions created before revision support was implemented. |
|
405 |
*/ |
|
406 |
function field_collection_update_7009(&$sandbox) { |
|
407 |
$items_per_pass = 10; |
|
408 |
$field_collection_fields = field_read_fields(array('type' => 'field_collection')); |
|
409 |
|
|
410 |
// If you don't have any field_collecton fields then skip this update. |
|
411 |
if (empty($field_collection_fields)) { |
|
412 |
return; |
|
413 |
} |
|
414 |
|
|
415 |
if (!isset($sandbox['current_field'])) { |
|
416 |
$sandbox['field_collection_fields'] = array_keys($field_collection_fields); |
|
417 |
$sandbox['current_field'] = 0; |
|
418 |
$sandbox['current_field_collection_item'] = 0; |
|
419 |
$sandbox['field_name'] = $sandbox['field_collection_fields'][$sandbox['current_field']]; |
|
420 |
$sandbox['inner_fields'] = field_read_instances(array('entity_type' => 'field_collection_item', 'bundle' => $sandbox['field_name'])); |
|
421 |
} |
|
422 |
|
|
423 |
// Find field collection items with duplicate revision ids. |
|
424 |
$query = db_select("field_revision_{$sandbox['field_name']}", 't') |
|
425 |
->fields('t', array("{$sandbox['field_name']}_revision_id")) |
|
426 |
->range($sandbox['current_field_collection_item'], $items_per_pass) |
|
427 |
->groupBy("t.{$sandbox['field_name']}_revision_id"); |
|
428 |
$query->addExpression("COUNT(t.{$sandbox['field_name']}_revision_id)", 'vidcount'); |
|
429 |
$query->havingCondition('vidcount', 2, '>='); |
|
430 |
$vids = $query->execute()->fetchCol(); |
|
431 |
|
|
432 |
// Each revision ID that occurs more than once. |
|
433 |
foreach ($vids as $field_collection_duplicated_revision_id) { |
|
434 |
// Find every instance of this revision ID. |
|
435 |
$copies = db_select("field_revision_{$sandbox['field_name']}", 't') |
|
436 |
->fields('t') |
|
437 |
->condition("{$sandbox['field_name']}_revision_id", $field_collection_duplicated_revision_id) |
|
438 |
->execute() |
|
439 |
->fetchAllAssoc('revision_id'); |
|
440 |
|
|
441 |
$first_copy = reset($copies); |
|
442 |
$field_collection_item_id = $first_copy->{"{$sandbox['field_name']}_value"}; |
|
443 |
|
|
444 |
// Find the currently used revision of this field collection item. |
|
445 |
$field_collection_item_current_revision = db_select('field_collection_item', 'fci') |
|
446 |
->fields('fci', array('revision_id')) |
|
447 |
->condition('item_id', $field_collection_item_id) |
|
448 |
->execute() |
|
449 |
->fetchField(); |
|
450 |
|
|
451 |
// Find new revisions of this field collection item that were made after |
|
452 |
// revisions were enabled in update_7003. |
|
453 |
$modern_revisions = db_select("field_revision_{$sandbox['field_name']}", 't') |
|
454 |
->fields('t') |
|
455 |
->condition("{$sandbox['field_name']}_revision_id", $field_collection_duplicated_revision_id, '<>') |
|
456 |
->condition("{$sandbox['field_name']}_value", $field_collection_item_id) |
|
457 |
->orderBy('revision_id') |
|
458 |
->execute() |
|
459 |
->fetchAllAssoc('revision_id'); |
|
460 |
|
|
461 |
// Intentionally skip the first instance as it doesn't need to be modified. |
|
462 |
while (FALSE !== ($row_to_replace = next($copies))) { |
|
463 |
$new_revision_id = _field_collection_update_7009_new_revision($field_collection_item_id, $row_to_replace, $sandbox['inner_fields'], $sandbox['field_name']); |
|
464 |
|
|
465 |
// Create copies of inner fields with new revision number. |
|
466 |
foreach ($sandbox['inner_fields'] as $field) { |
|
467 |
// Get the data to copy. |
|
468 |
$data_rows = db_select("field_revision_{$field['field_name']}", 't') |
|
469 |
->fields('t') |
|
470 |
->condition('entity_type', 'field_collection_item') |
|
471 |
->condition('revision_id', $field_collection_duplicated_revision_id) |
|
472 |
->execute(); |
|
473 |
|
|
474 |
// Add new copy of data with new revision id. |
|
475 |
while ($each_row = $data_rows->fetchAssoc()) { |
|
476 |
$each_row['revision_id'] = $new_revision_id; |
|
477 |
db_insert("field_revision_{$field['field_name']}") |
|
478 |
->fields(array_keys($each_row), array_values($each_row)) |
|
479 |
->execute(); |
|
480 |
} |
|
481 |
} |
|
482 |
|
|
483 |
// Update the host's field data with new revision number. |
|
484 |
db_update("field_revision_{$sandbox['field_name']}") |
|
485 |
->fields(array("{$sandbox['field_name']}_revision_id" => $new_revision_id)) |
|
486 |
->condition('entity_type', $row_to_replace->entity_type) |
|
487 |
->condition('revision_id', $row_to_replace->revision_id) |
|
488 |
->condition('delta', $row_to_replace->delta) |
|
489 |
->condition('language', $row_to_replace->language) |
|
490 |
->execute(); |
|
491 |
} |
|
492 |
|
|
493 |
if ($field_collection_item_current_revision == $field_collection_duplicated_revision_id) { |
|
494 |
_field_collection_update_7009_update_data($new_revision_id, $field_collection_duplicated_revision_id); |
|
495 |
|
|
496 |
// Update the current field collection item data in its host. |
|
497 |
db_update("field_data_{$sandbox['field_name']}") |
|
498 |
->fields(array('revision_id' => $new_revision)) |
|
499 |
->condition('revision_id', $old_revision) |
|
500 |
->condition('entity_type', $row_to_replace->entity_type) |
|
501 |
->execute(); |
|
502 |
} |
|
503 |
|
|
504 |
foreach ($modern_revisions as $each_modern_revision) { |
|
505 |
$new_revision_id = _field_collection_update_7009_new_revision($field_collection_item_id, $each_modern_revision, $sandbox['inner_fields'], $sandbox['field_name']); |
|
506 |
|
|
507 |
// Update inner fields with new revision number. |
|
508 |
foreach ($sandbox['inner_fields'] as $field) { |
|
509 |
db_update("field_revision_{$field['field_name']}") |
|
510 |
->fields(array('revision_id' => $new_revision_id)) |
|
511 |
->condition('revision_id', $each_modern_revision->{$sandbox['field_name'] . '_revision_id'}) |
|
512 |
->condition('entity_type', 'field_collection_item') |
|
513 |
->execute(); |
|
514 |
} |
|
515 |
|
|
516 |
// Update the host's field data with new revision number. |
|
517 |
db_update("field_revision_{$sandbox['field_name']}") |
|
518 |
->fields(array("{$sandbox['field_name']}_revision_id" => $new_revision_id)) |
|
519 |
->condition('entity_type', $each_modern_revision->entity_type) |
|
520 |
->condition('revision_id', $each_modern_revision->revision_id) |
|
521 |
->condition('delta', $each_modern_revision->delta) |
|
522 |
->condition('language', $each_modern_revision->language) |
|
523 |
->execute(); |
|
524 |
|
|
525 |
if ($field_collection_item_current_revision == $each_modern_revision->{"{$sandbox['field_name']}_revision_id"}) { |
|
526 |
_field_collection_update_7009_update_data($new_revision_id, $each_modern_revision->{"{$sandbox['field_name']}_revision_id"}); |
|
527 |
|
|
528 |
// Update the current field collection item data in its host. |
|
529 |
db_update("field_data_{$sandbox['field_name']}") |
|
530 |
->fields(array('revision_id' => $new_revision)) |
|
531 |
->condition('revision_id', $old_revision) |
|
532 |
->condition('entity_type', $each_modern_revision->entity_type) |
|
533 |
->execute(); |
|
534 |
} |
|
535 |
|
|
536 |
// Remove old copy of revision. |
|
537 |
db_delete('field_collection_item_revision') |
|
538 |
->condition('revision_id', $each_modern_revision->revision_id) |
|
539 |
->execute(); |
|
540 |
} |
|
541 |
|
|
542 |
$sandbox['current_field_collection_item']++; |
|
543 |
} |
|
544 |
|
|
545 |
$sandbox['#finished'] = 0; |
|
546 |
|
|
547 |
if (count($vids) < $items_per_pass) { |
|
548 |
$sandbox['current_field']++; |
|
549 |
if ($sandbox['current_field'] == count($sandbox['field_collection_fields'])) { |
|
550 |
$sandbox['#finished'] = 1; |
|
551 |
return; |
|
552 |
} |
|
553 |
$sandbox['current_field_collection_item'] = 0; |
|
554 |
$sandbox['field_name'] = $sandbox['field_collection_fields'][$sandbox['current_field']]; |
|
555 |
$sandbox['inner_fields'] = field_read_instances(array('entity_type' => 'field_collection_item', 'bundle' => $sandbox['field_name'])); |
|
556 |
} |
|
557 |
} |
|
558 |
|
|
559 |
function _field_collection_update_7009_new_revision($field_collection_item_id, $row_to_replace, $inner_fields, $field_name) { |
|
560 |
// Add to field_collection_item_revision table. |
|
561 |
$new_revision_id = db_insert('field_collection_item_revision') |
|
562 |
->fields(array('item_id'), array($field_collection_item_id)) |
|
563 |
->execute(); |
|
564 |
|
|
565 |
return $new_revision_id; |
|
566 |
} |
|
567 |
|
|
568 |
function _field_collection_update_7009_update_data($new_revision, $old_revision) { |
|
569 |
// Update the current field collection item. |
|
570 |
db_update('field_collection_item') |
|
571 |
->fields(array('revision_id' => $new_revision)) |
|
572 |
->condition('revision_id', $old_revision) |
|
573 |
->execute(); |
|
574 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules