| 12345678910111213141516171819202122232425262728293031 | 
							- <?php
 
- use Drupal\Core\Database\Database;
 
- /**
 
-  * Transfer logouts time settings from configs to states.
 
-  */
 
- function autologout_update_8001(&$sandbox) {
 
-   $result = Database::getConnection()
 
-     ->select('config', 'c')
 
-     ->fields('c', ['name', 'data'])
 
-     ->condition('name', 'autologout.user.%', 'LIKE')
 
-     ->execute()->fetchAll();
 
-   if (!isset($sandbox['current'])) {
 
-     $sandbox['current'] = 0;
 
-     $sandbox['max'] = count($result);
 
-   }
 
-   $limit = 5;
 
-   $result = array_slice($result, $sandbox['current'], $limit);
 
-   foreach ($result as $row) {
 
-     $key = $row->name;
 
-     // User uid is a part of the key after. E.g. autologout.user.1 for user 1.
 
-     $user_id = (substr($key, 16));
 
-     $data = unserialize($row->data);
 
-     \Drupal::service('user.data')->set('autologout', $user_id, 'timeout', $data['timeout']);
 
-     \Drupal::service('user.data')->set('autologout', $user_id, 'enabled', $data['enabled']);
 
-     $sandbox['current']++;
 
-   }
 
-   $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['current'] / $sandbox['max']);
 
-   if ($sandbox['#finished'] >= 1) {
 
-     return t('Autologout settings are successfully updated. Updated @users', ["@users" => $sandbox['max']]);
 
-   }
 
- }
 
 
  |