function system_update_10100
Remove the year 2038 date limitation.
File
-
core/
modules/ system/ system.install, line 1737
Code
function system_update_10100(&$sandbox = NULL) {
$connection = \Drupal::database();
$schema = $connection->schema();
// Update sessions table.
if ($schema->tableExists('sessions') && $connection->databaseType() != 'sqlite') {
$new = [
'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'big',
];
$schema->changeField('sessions', 'timestamp', 'timestamp', $new);
}
// Update batch table.
if ($schema->tableExists('batch') && $connection->databaseType() != 'sqlite') {
$new = [
'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.',
'type' => 'int',
'not null' => TRUE,
'size' => 'big',
];
$schema->changeField('batch', 'timestamp', 'timestamp', $new);
}
// Update flood table.
if ($schema->tableExists('flood') && $connection->databaseType() != 'sqlite') {
$new = [
'timestamp' => [
'description' => 'Timestamp of the event.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'big',
],
'expiration' => [
'description' => 'Expiration timestamp. Expired events are purged on cron run.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'big',
],
];
foreach ($new as $column_name => $value) {
$schema->changeField('flood', $column_name, $column_name, $value);
}
}
// Update queue table.
if ($schema->tableExists('queue') && $connection->databaseType() != 'sqlite') {
$new = [
'expire' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp when the claim lease expires on the item.',
'size' => 'big',
],
'created' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Timestamp when the item was created.',
'size' => 'big',
],
];
foreach ($new as $column_name => $value) {
$schema->changeField('queue', $column_name, $column_name, $value);
}
}
// Update cache tables.
$cache_tables = $schema->findTables('cache_%');
$cache_tables = array_filter($cache_tables, function ($cache_tables) {
return str_starts_with($cache_tables, 'cache_');
});
if ($connection->databaseType() != 'sqlite') {
foreach (array_keys($cache_tables) as $table) {
// If the table has no expire column there is nothing to do. This can
// happen if a site has tables starting with cache_ that are not cache
// bins.
if (!$schema->fieldExists($table, 'expire')) {
continue;
}
// Truncate cache tables. They will be flushed anyway at the end of
// database updates, but emptying the tables now will boost the schema
// changes.
$connection->truncate($table)
->execute();
$new = [
'description' => 'A Unix timestamp indicating when the cache entry should expire, or ' . Cache::PERMANENT . ' for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'big',
];
$schema->changeField($table, 'expire', 'expire', $new);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.