This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
/
openy.post_update.php
51 lines (46 loc) · 1.74 KB
/
openy.post_update.php
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
<?php
/**
* @file
* Post update functions for Open Y Distribution.
*/
/**
* Cleanup upgrade path message errors.
*
* We cannot prevent this upgrade path messages from being created.
*/
function openy_post_update_cleanup_update_path_messages(&$sandbox) {
// Here we clean up messages that appeared in the message log during
// last 5 minutes. These messages are generated by
// node_post_update_configure_status_field_widget() and cannot be handled
// by upgrade path tool, because Drupal Core automatically
// increases weight which doesn't match database.
// @see node_post_update_configure_status_field_widget()
$range = strtotime("-5 minutes");
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current'] = 0;
$sandbox['max'] = \Drupal::entityQuery('openy_upgrade_log')
->condition('name', 'core.entity_form_display.node', 'STARTS_WITH')
->condition('created', $range, '>')
->count()
->execute();
// Limit updates for non-acquia environments.
if (empty($_ENV['AH_SITE_ENVIRONMENT'])) {
$sandbox['max'] = min($sandbox['max'], 20);
}
}
$ids = \Drupal::entityQuery('openy_upgrade_log')
->condition('name', 'core.entity_form_display.node', 'STARTS_WITH')
->condition('created', $range, '>')
->range(0, 20)
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage('openy_upgrade_log');
$entities = $storage_handler->loadMultiple($ids);
foreach ($entities as $entity) {
$sandbox['progress']++;
$sandbox['current'] = $entity->id();
$entity->delete();
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
return t('@count Entities were deleted.', ['@count' => $sandbox['max']]);
}