summaryrefslogtreecommitdiffstats
path: root/core/modules/system/system.install
blob: eeb8616d98842de5151c243b863d7631dac0dad1 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
<?php

use Drupal\Core\Database\Database;

/**
 * @file
 * Install, update and uninstall functions for the system module.
 */

/**
 * Test and report Drupal installation requirements.
 *
 * @param $phase
 *   The current system installation phase.
 * @return
 *   An array of system requirements.
 */
function system_requirements($phase) {
  global $base_url;
  $requirements = array();
  // Ensure translations don't break during installation.
  $t = get_t();

  // Report Drupal version
  if ($phase == 'runtime') {
    $requirements['drupal'] = array(
      'title' => $t('Drupal'),
      'value' => VERSION,
      'severity' => REQUIREMENT_INFO,
      'weight' => -10,
    );

    // Display the currently active installation profile, if the site
    // is not running the default installation profile.
    $profile = drupal_get_profile();
    if ($profile != 'standard') {
      $info = system_get_info('module', $profile);
      $requirements['install_profile'] = array(
        'title' => $t('Installation profile'),
        'value' => $t('%profile_name (%profile-%version)', array(
          '%profile_name' => $info['name'],
          '%profile' => $profile,
          '%version' => $info['version']
        )),
        'severity' => REQUIREMENT_INFO,
        'weight' => -9
      );
    }
  }

  // Web server information.
  $software = $_SERVER['SERVER_SOFTWARE'];
  $requirements['webserver'] = array(
    'title' => $t('Web server'),
    'value' => $software,
  );

  // Test PHP version and show link to phpinfo() if it's available
  $phpversion = phpversion();
  if (function_exists('phpinfo')) {
    $requirements['php'] = array(
      'title' => $t('PHP'),
      'value' => ($phase == 'runtime') ? $phpversion .' ('. l($t('more information'), 'admin/reports/status/php') .')' : $phpversion,
    );
  }
  else {
    $requirements['php'] = array(
      'title' => $t('PHP'),
      'value' => $phpversion,
      'description' => $t('The phpinfo() function has been disabled for security reasons. To see your server\'s phpinfo() information, change your PHP settings or contact your server administrator. For more information, <a href="@phpinfo">Enabling and disabling phpinfo()</a> handbook page.', array('@phpinfo' => 'http://drupal.org/node/243993')),
      'severity' => REQUIREMENT_INFO,
    );
  }

  if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
    $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
    $requirements['php']['severity'] = REQUIREMENT_ERROR;
    // If PHP is old, it's not safe to continue with the requirements check.
    return $requirements;
  }

  // Test PHP register_globals setting.
  $requirements['php_register_globals'] = array(
    'title' => $t('PHP register globals'),
  );
  $register_globals = trim(ini_get('register_globals'));
  // Unfortunately, ini_get() may return many different values, and we can't
  // be certain which values mean 'on', so we instead check for 'not off'
  // since we never want to tell the user that their site is secure
  // (register_globals off), when it is in fact on. We can only guarantee
  // register_globals is off if the value returned is 'off', '', or 0.
  if (!empty($register_globals) && strtolower($register_globals) != 'off') {
    $requirements['php_register_globals']['description'] = $t('<em>register_globals</em> is enabled. Drupal requires this configuration directive to be disabled. Your site may not be secure when <em>register_globals</em> is enabled. The PHP manual has instructions for <a href="@url">how to change configuration settings</a>.', array('@url' => 'http://php.net/configuration.changes'));
    $requirements['php_register_globals']['severity'] = REQUIREMENT_ERROR;
    $requirements['php_register_globals']['value'] = $t("Enabled ('@value')", array('@value' => $register_globals));
  }
  else {
    $requirements['php_register_globals']['value'] = $t('Disabled');
  }

  // Test for PHP extensions.
  $requirements['php_extensions'] = array(
    'title' => $t('PHP extensions'),
  );

  $missing_extensions = array();
  $required_extensions = array(
    'date',
    'dom',
    'filter',
    'gd',
    'hash',
    'json',
    'pcre',
    'pdo',
    'session',
    'SimpleXML',
    'SPL',
    'tokenizer',
    'xml',
  );
  foreach ($required_extensions as $extension) {
    if (!extension_loaded($extension)) {
      $missing_extensions[] = $extension;
    }
  }

  if (!empty($missing_extensions)) {
    $description = $t('Drupal requires you to enable the PHP extensions in the following list (see the <a href="@system_requirements">system requirements page</a> for more information):', array(
      '@system_requirements' => 'http://drupal.org/requirements',
    ));

    $description .= theme('item_list', array('items' => $missing_extensions));

    $requirements['php_extensions']['value'] = $t('Disabled');
    $requirements['php_extensions']['severity'] = REQUIREMENT_ERROR;
    $requirements['php_extensions']['description'] = $description;
  }
  else {
    $requirements['php_extensions']['value'] = $t('Enabled');
  }

  if ($phase == 'install' || $phase == 'update') {
    // Test for PDO (database).
    $requirements['database_extensions'] = array(
      'title' => $t('Database support'),
    );

    // Make sure PDO is available.
    $database_ok = extension_loaded('pdo');
    if (!$database_ok) {
      $pdo_message = $t('Your web server does not appear to support PDO (PHP Data Objects). Ask your hosting provider if they support the native PDO extension. See the <a href="@link">system requirements</a> page for more information.', array(
        '@link' => 'http://drupal.org/requirements/pdo',
      ));
    }
    else {
      // Make sure at least one supported database driver exists.
      $drivers = drupal_detect_database_types();
      if (empty($drivers)) {
        $database_ok = FALSE;
        $pdo_message = $t('Your web server does not appear to support any common PDO database extensions. Check with your hosting provider to see if they support PDO (PHP Data Objects) and offer any databases that <a href="@drupal-databases">Drupal supports</a>.', array(
          '@drupal-databases' => 'http://drupal.org/node/270#database',
        ));
      }
      // Make sure the native PDO extension is available, not the older PEAR
      // version. (See install_verify_pdo() for details.)
      if (!defined('PDO::ATTR_DEFAULT_FETCH_MODE')) {
        $database_ok = FALSE;
        $pdo_message = $t('Your web server seems to have the wrong version of PDO installed. Drupal requires the PDO extension from PHP core. This system has the older PECL version. See the <a href="@link">system requirements</a> page for more information.', array(
          '@link' => 'http://drupal.org/requirements/pdo#pecl',
        ));
      }
    }

    if (!$database_ok) {
      $requirements['database_extensions']['value'] = $t('Disabled');
      $requirements['database_extensions']['severity'] = REQUIREMENT_ERROR;
      $requirements['database_extensions']['description'] = $pdo_message;
    }
    else {
      $requirements['database_extensions']['value'] = $t('Enabled');
    }
  }
  else {
    // Database information.
    $class = Database::getConnection()->getDriverClass('Install\\Tasks');
    $tasks = new $class();
    $requirements['database_system'] = array(
      'title' => $t('Database system'),
      'value' => $tasks->name(),
    );
    $requirements['database_system_version'] = array(
      'title' => $t('Database system version'),
      'value' => Database::getConnection()->version(),
    );
  }

  // Test PHP memory_limit
  $memory_limit = ini_get('memory_limit');
  $requirements['php_memory_limit'] = array(
    'title' => $t('PHP memory limit'),
    'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
  );

  if (!drupal_check_memory_limit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
    $description = '';
    if ($phase == 'install') {
      $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', array('%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT));
    }
    elseif ($phase == 'update') {
      $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', array('%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT));
    }
    elseif ($phase == 'runtime') {
      $description = $t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT));
    }

    if (!empty($description)) {
      if ($php_ini_path = get_cfg_var('cfg_file_path')) {
        $description .= ' ' . $t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array('%configuration-file' => $php_ini_path));
      }
      else {
        $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
      }

      $requirements['php_memory_limit']['description'] = $description . ' ' . $t('For more information, see the online handbook entry for <a href="@memory-limit">increasing the PHP memory limit</a>.', array('@memory-limit' => 'http://drupal.org/node/207036'));
      $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
    }
  }

  // Test configuration files and directory for writability.
  if ($phase == 'runtime') {
    $conf_errors = array();
    $conf_path = conf_path();
    if (!drupal_verify_install_file($conf_path, FILE_NOT_WRITABLE, 'dir')) {
      $conf_errors[] = $t("The directory %file is not protected from modifications and poses a security risk. You must change the directory's permissions to be non-writable.", array('%file' => $conf_path));
    }
    foreach (array('settings.php', 'settings.local.php') as $conf_file) {
      $full_path = $conf_path . '/' . $conf_file;
      if (file_exists($full_path) && !drupal_verify_install_file($full_path, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE)) {
        $conf_errors[] = $t("The file %file is not protected from modifications and poses a security risk. You must change the file's permissions to be non-writable.", array('%file' => $full_path));
      }
    }
    if (!empty($conf_errors)) {
      if (count($conf_errors) == 1) {
        $description = $conf_errors[0];
      }
      else {
        $description = theme('item_list', array('items' => $conf_errors));
      }
      $requirements['settings.php'] = array(
        'value' => $t('Not protected'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $description,
      );
    }
    else {
      $requirements['settings.php'] = array(
        'value' => $t('Protected'),
      );
    }
    $requirements['settings.php']['title'] = $t('Configuration files');
  }

  // Report cron status.
  if ($phase == 'runtime') {
    $cron_config = config('system.cron');
    // Cron warning threshold defaults to two days.
    $threshold_warning = $cron_config->get('threshold.requirements_warning');
    // Cron error threshold defaults to two weeks.
    $threshold_error = $cron_config->get('threshold.requirements_error');
    // Cron configuration help text.
    $help = $t('For more information, see the online handbook entry for <a href="@cron-handbook">configuring cron jobs</a>.', array('@cron-handbook' => 'http://drupal.org/cron'));

    // Determine when cron last ran.
    $cron_last = state()->get('system.cron_last');
    if (!is_numeric($cron_last)) {
      $cron_last = variable_get('install_time', 0);
    }

    // Determine severity based on time since cron last ran.
    $severity = REQUIREMENT_INFO;
    if (REQUEST_TIME - $cron_last > $threshold_error) {
      $severity = REQUIREMENT_ERROR;
    }
    elseif (REQUEST_TIME - $cron_last > $threshold_warning) {
      $severity = REQUIREMENT_WARNING;
    }

    // Set summary and description based on values determined above.
    $summary = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last)));
    $description = '';
    if ($severity != REQUIREMENT_INFO) {
      $description = $t('Cron has not run recently.') . ' ' . $help;
    }

    $description .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
    $description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . state()->get('system.cron_key'), array('absolute' => TRUE))));

    $requirements['cron'] = array(
      'title' => $t('Cron maintenance tasks'),
      'severity' => $severity,
      'value' => $summary,
      'description' => $description
    );
  }
  if ($phase != 'install') {
    $filesystem_config = config('system.file');
    $directories = array(
      variable_get('file_public_path', conf_path() . '/files'),
      // By default no private files directory is configured. For private files
      // to be secure the admin needs to provide a path outside the webroot.
      $filesystem_config->get('path.private'),
      file_directory_temp(),
    );
  }

  // During an install we need to make assumptions about the file system
  // unless overrides are provided in settings.php.
  if ($phase == 'install') {
    global $conf;
    $directories = array();
    if (!empty($conf['file_public_path'])) {
      $directories[] = $conf['file_public_path'];
    }
    else {
      // If we are installing Drupal, the settings.php file might not exist yet
      // in the intended conf_path() directory, so don't require it. The
      // conf_path() cache must also be reset in this case.
      $directories[] = conf_path(FALSE, TRUE) . '/files';
    }
    if (!empty($conf['system.file']['path.private'])) {
      $directories[] = $conf['system.file']['path.private'];
    }
    if (!empty($conf['system.file']['path.temporary'])) {
      $directories[] = $conf['system.file']['path.temporary'];
    }
    else {
      // If the temporary directory is not overridden use an appropriate
      // temporary path for the system.
      $directories[] = file_directory_os_temp();
    }
  }

  // Check the config directory if it is defined in settings.php. If it isn't
  // defined, the installer will create a valid config directory later, but
  // during runtime we must always display an error.
  if (!empty($GLOBALS['config_directories'])) {
    $directories[] = config_get_config_directory(CONFIG_ACTIVE_DIRECTORY);
    $directories[] = config_get_config_directory(CONFIG_STAGING_DIRECTORY);
  }
  elseif ($phase != 'install') {
    $requirements['config directories'] = array(
      'title' => $t('Configuration directories'),
      'value' => $t('Not present'),
      'description' => $t('Your %file file must define the $config_directories variable as an array containing the name of a directories in which configuration files can be written.', array('%file' => conf_path() . '/settings.php')),
      'severity' => REQUIREMENT_ERROR,
    );
  }

  $requirements['file system'] = array(
    'title' => $t('File system'),
  );

  $error = '';
  // For installer, create the directories if possible.
  foreach ($directories as $directory) {
    if (!$directory) {
      continue;
    }
    if ($phase == 'install') {
      file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
    }
    $is_writable = is_writable($directory);
    $is_directory = is_dir($directory);
    if (!$is_writable || !$is_directory) {
      $description = '';
      $requirements['file system']['value'] = $t('Not writable');
      if (!$is_directory) {
        $error .= $t('The directory %directory does not exist.', array('%directory' => $directory)) . ' ';
      }
      else {
        $error .= $t('The directory %directory is not writable.', array('%directory' => $directory)) . ' ';
      }
      // The files directory requirement check is done only during install and runtime.
      if ($phase == 'runtime') {
        $description = $error . $t('You may need to set the correct directory at the <a href="@admin-file-system">file system settings page</a> or change the current directory\'s permissions so that it is writable.', array('@admin-file-system' => url('admin/config/media/file-system')));
      }
      elseif ($phase == 'install') {
        // For the installer UI, we need different wording. 'value' will
        // be treated as version, so provide none there.
        $description = $error . $t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href="@handbook_url">online handbook</a>.', array('@handbook_url' => 'http://drupal.org/server-permissions'));
        $requirements['file system']['value'] = '';
      }
      if (!empty($description)) {
        $requirements['file system']['description'] = $description;
        $requirements['file system']['severity'] = REQUIREMENT_ERROR;
      }
    }
    else {
      if (file_default_scheme() == 'public') {
        $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)');
      }
      else {
        $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)');
      }
    }
  }

  // See if updates are available in update.php.
  if ($phase == 'runtime') {
    $requirements['update'] = array(
      'title' => $t('Database updates'),
      'value' => $t('Up to date'),
    );

    // Check installed modules.
    foreach (drupal_container()->get('module_handler')->getModuleList() as $module => $filename) {
      $updates = drupal_get_schema_versions($module);
      if ($updates !== FALSE) {
        $default = drupal_get_installed_schema_version($module);
        if (max($updates) > $default) {
          $requirements['update']['severity'] = REQUIREMENT_ERROR;
          $requirements['update']['value'] = $t('Out of date');
          $requirements['update']['description'] = $t('Some modules have database schema updates to install. You should run the <a href="@update">database update script</a> immediately.', array('@update' => base_path() . 'core/update.php'));
          break;
        }
      }
    }
  }

  // Verify the update.php access setting
  if ($phase == 'runtime') {
    if (settings()->get('update_free_access')) {
      $requirements['update access'] = array(
        'value' => $t('Not protected'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('The update.php script is accessible to everyone without authentication check, which is a security risk. You must change the @settings_name value in your settings.php back to FALSE.', array('@settings_name' => '$settings[\'update_free_access\']')),
      );
    }
    else {
      $requirements['update access'] = array(
        'value' => $t('Protected'),
      );
    }
    $requirements['update access']['title'] = $t('Access to update.php');
  }

  // Display an error if a newly introduced dependency in a module is not resolved.
  if ($phase == 'update') {
    $profile = drupal_get_profile();
    $files = system_rebuild_module_data();
    foreach ($files as $module => $file) {
      // Ignore disabled modules and installation profiles.
      if (!$file->status || $module == $profile) {
        continue;
      }
      // Check the module's PHP version.
      $name = $file->info['name'];
      $php = $file->info['php'];
      if (version_compare($php, PHP_VERSION, '>')) {
        $requirements['php']['description'] .= $t('@name requires at least PHP @version.', array('@name' => $name, '@version' => $php));
        $requirements['php']['severity'] = REQUIREMENT_ERROR;
      }
      // Check the module's required modules.
      foreach ($file->requires as $requirement) {
        $required_module = $requirement['name'];
        // Check if the module exists.
        if (!isset($files[$required_module])) {
          $requirements["$module-$required_module"] = array(
            'title' => $t('Unresolved dependency'),
            'description' => $t('@name requires this module.', array('@name' => $name)),
            'value' => t('@required_name (Missing)', array('@required_name' => $required_module)),
            'severity' => REQUIREMENT_ERROR,
          );
          continue;
        }
        // Check for an incompatible version.
        $required_file = $files[$required_module];
        $required_name = $required_file->info['name'];
        $version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $required_file->info['version']);
        $compatibility = drupal_check_incompatibility($requirement, $version);
        if ($compatibility) {
          $compatibility = rtrim(substr($compatibility, 2), ')');
          $requirements["$module-$required_module"] = array(
            'title' => $t('Unresolved dependency'),
            'description' => $t('@name requires this module and version. Currently using @required_name version @version', array('@name' => $name, '@required_name' => $required_name, '@version' => $version)),
            'value' => t('@required_name (Version @compatibility required)', array('@required_name' => $required_name, '@compatibility' => $compatibility)),
            'severity' => REQUIREMENT_ERROR,
          );
          continue;
        }
      }
    }
  }

  // Test Unicode library
  include_once DRUPAL_ROOT . '/core/includes/unicode.inc';
  $requirements = array_merge($requirements, unicode_requirements());

  if ($phase == 'runtime') {
    // Check for update status module.
    if (!module_exists('update')) {
      $requirements['update status'] = array(
        'value' => $t('Not enabled'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('Update notifications are not enabled. It is <strong>highly recommended</strong> that you enable the Update Manager module from the <a href="@module">module administration page</a> in order to stay up-to-date on new releases. For more information, <a href="@update">Update status handbook page</a>.', array('@update' => 'http://drupal.org/documentation/modules/update', '@module' => url('admin/modules'))),
      );
    }
    else {
      $requirements['update status'] = array(
        'value' => $t('Enabled'),
      );
    }
    $requirements['update status']['title'] = $t('Update notifications');
  }

  return $requirements;
}

/**
 * Implements hook_install().
 */
function system_install() {
  // Enable and set the default theme. Can't use theme_enable() this early in
  // installation.
  config_install_default_config('theme', 'stark');
  config('system.theme')
    ->set('default', 'stark')
    ->save();

  // Populate the cron key state variable.
  $cron_key = drupal_hash_base64(drupal_random_bytes(55));
  state()->set('system.cron_key', $cron_key);
}

/**
 * Implements hook_schema().
 */
function system_schema() {
  // NOTE: {variable} needs to be created before all other tables, as
  // some database drivers, e.g. Oracle and DB2, will require variable_get()
  // and variable_set() for overcoming some database specific limitations.
  $schema['variable'] = array(
    'description' => 'Named variable/value pairs created by Drupal core or any other module or theme. All variables are cached in memory at the start of every Drupal request so developers should not be careless about what is stored here.',
    'fields' => array(
      'name' => array(
        'description' => 'The name of the variable.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The value of the variable.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ),
    ),
    'primary key' => array('name'),
  );

  $schema['batch'] = array(
    'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
    'fields' => array(
      'bid' => array(
        'description' => 'Primary Key: Unique batch ID.',
        // This is not a serial column, to allow both progressive and
        // non-progressive batches. See batch_process().
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'token' => array(
        'description' => "A string token generated against the current user's session id and the batch id, used to ensure that only the user who submitted the batch can effectively access it.",
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
      ),
      'timestamp' => array(
        'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.',
        'type' => 'int',
        'not null' => TRUE,
      ),
      'batch' => array(
        'description' => 'A serialized array containing the processing data for the batch.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
    ),
    'primary key' => array('bid'),
    'indexes' => array(
      'token' => array('token'),
    ),
  );

  $schema['cache_tags'] = array(
    'description' => 'Cache table for tracking cache tags related to the cache bin.',
    'fields' => array(
      'tag' => array(
        'description' => 'Namespace-prefixed tag string.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'invalidations' => array(
        'description' => 'Number incremented when the tag is invalidated.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'deletions' => array(
        'description' => 'Number incremented when the tag is deleted.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('tag'),
  );

  $schema['cache'] = array(
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
    'fields' => array(
      'cid' => array(
        'description' => 'Primary Key: Unique cache ID.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => 'A collection of data to cache.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'expire' => array(
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'serialized' => array(
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tags' => array(
        'description' => 'Space-separated list of cache tags for this entry.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'checksum_invalidations' => array(
        'description' => 'The tag invalidation sum when this entry was saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'checksum_deletions' => array(
        'description' => 'The tag deletion sum when this entry was saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'expire' => array('expire'),
    ),
    'primary key' => array('cid'),
  );
  $schema['cache_bootstrap'] = $schema['cache'];
  $schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.';
  $schema['cache_config'] = $schema['cache'];
  $schema['cache_config']['description'] = 'Cache table for configuration data.';
  $schema['cache_form'] = $schema['cache'];
  $schema['cache_form']['description'] = 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.';
  $schema['cache_page'] = $schema['cache'];
  $schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.';
  $schema['cache_menu'] = $schema['cache'];
  $schema['cache_menu']['description'] = 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.';
  $schema['cache_path'] = $schema['cache'];
  $schema['cache_path']['description'] = 'Cache table for path alias lookup.';

  $schema['flood'] = array(
    'description' => 'Flood controls the threshold of events, such as the number of contact attempts.',
    'fields' => array(
      'fid' => array(
        'description' => 'Unique flood event ID.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'event' => array(
        'description' => 'Name of event (e.g. contact).',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'identifier' => array(
        'description' => 'Identifier of the visitor, such as an IP address or hostname.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'timestamp' => array(
        'description' => 'Timestamp of the event.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'expiration' => array(
        'description' => 'Expiration timestamp. Expired events are purged on cron run.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('fid'),
    'indexes' => array(
      'allow' => array('event', 'identifier', 'timestamp'),
      'purge' => array('expiration'),
    ),
  );

  $schema['key_value'] = array(
    'description' => 'Generic key-value storage table. See state() for an example.',
    'fields' => array(
      'collection' => array(
        'description' => 'A named collection of key and value pairs.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The value.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ),
    ),
    'primary key' => array('collection', 'name'),
  );

  $schema['key_value_expire'] = array(
    'description' => 'Generic key/value storage table with an expiration.',
    'fields' => array(
      'collection' => array(
        'description' => 'A named collection of key and value pairs.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        // KEY is an SQL reserved word, so use 'name' as the key's field name.
        'description' => 'The key of the key/value pair.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'value' => array(
        'description' => 'The value of the key/value pair.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ),
      'expire' => array(
        'description' => 'The time since Unix epoch in seconds when this item expires. Defaults to the maximum possible time.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 2147483647,
      ),
    ),
    'primary key' => array('collection', 'name'),
    'indexes' => array(
      'all' => array('name', 'collection', 'expire'),
    ),
  );

  $schema['menu_router'] = array(
    'description' => 'Maps paths to various callbacks (access, page and title)',
    'fields' => array(
      'path' => array(
        'description' => 'Primary Key: the Drupal path this entry describes',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'load_functions' => array(
        'description' => 'A serialized array of function names (like node_load) to be called to load an object corresponding to a part of the current path.',
        'type' => 'blob',
        'not null' => TRUE,
      ),
      'to_arg_functions' => array(
        'description' => 'A serialized array of function names (like user_uid_optional_to_arg) to be called to replace a part of the router path with another string.',
        'type' => 'blob',
        'not null' => TRUE,
      ),
      'access_callback' => array(
        'description' => 'The callback which determines the access to this router path. Defaults to user_access.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'access_arguments' => array(
        'description' => 'A serialized array of arguments for the access callback.',
        'type' => 'blob',
        'not null' => FALSE,
      ),
      'page_callback' => array(
        'description' => 'The name of the function that renders the page.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'page_arguments' => array(
        'description' => 'A serialized array of arguments for the page callback.',
        'type' => 'blob',
        'not null' => FALSE,
      ),
      'fit' => array(
        'description' => 'A numeric representation of how specific the path is.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'number_parts' => array(
        'description' => 'Number of parts in this router path.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'small',
      ),
      'context' => array(
        'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tab_parent' => array(
        'description' => 'Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'tab_root' => array(
        'description' => 'Router path of the closest non-tab parent page. For pages that are not local tasks, this will be the same as the path.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'title' => array(
        'description' => 'The title for the current page, or the title for the tab if this is a local task.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'title_callback' => array(
        'description' => 'A function which will alter the title. Defaults to t()',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'title_arguments' => array(
        'description' => 'A serialized array of arguments for the title callback. If empty, the title will be used as the sole argument for the title callback.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'theme_callback' => array(
        'description' => 'A function which returns the name of the theme that will be used to render this page. If left empty, the default theme will be used.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'theme_arguments' => array(
        'description' => 'A serialized array of arguments for the theme callback.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'type' => array(
        'description' => 'Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'description' => array(
        'description' => 'A description of this item.',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'description_callback' => array(
        'description' => 'A function which will alter the description. Defaults to t().',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description_arguments' => array(
        'description' => 'A serialized array of arguments for the description callback. If empty, the description will be used as the sole argument for the description callback.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'position' => array(
        'description' => 'The position of the block (left or right) on the system administration page for this item.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'weight' => array(
        'description' => 'Weight of the element. Lighter weights are higher up, heavier weights go down.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'include_file' => array(
        'description' => 'The file to include for this element, usually the page callback function lives in this file.',
        'type' => 'text',
        'size' => 'medium',
      ),
    ),
    'indexes' => array(
      'fit' => array('fit'),
      'tab_parent' => array(array('tab_parent', 64), 'weight', 'title'),
      'tab_root_weight_title' => array(array('tab_root', 64), 'weight', 'title'),
    ),
    'primary key' => array('path'),
  );

  $schema['queue'] = array(
    'description' => 'Stores items in queues.',
    'fields' => array(
      'item_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique item ID.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The queue name.',
      ),
      'data' => array(
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'The arbitrary data for the item.',
      ),
      'expire' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Timestamp when the claim lease expires on the item.',
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Timestamp when the item was created.',
      ),
    ),
    'primary key' => array('item_id'),
    'indexes' => array(
      'name_created' => array('name', 'created'),
      'expire' => array('expire'),
    ),
  );

  $schema['router'] = array(
    'description' => 'Maps paths to various callbacks (access, page and title)',
    'fields' => array(
      'name' => array(
        'description' => 'Primary Key: Machine name of this route',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'pattern' => array(
        'description' => 'The path pattern for this URI',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'pattern_outline' => array(
        'description' => 'The pattern',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'route_set' => array(
        'description' => 'The route set grouping to which a route belongs.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'fit' => array(
        'description' => 'A numeric representation of how specific the path is.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'route' => array(
        'description' => 'A serialized Route object',
        'type' => 'text',
      ),
      'number_parts' => array(
        'description' => 'Number of parts in this router path.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'small',
      ),
    ),
    'indexes' => array(
      'fit' => array('fit'),
      'pattern_outline' => array('pattern_outline'),
      'route_set' => array('route_set'),
    ),
    'primary key' => array('name'),
  );

  $schema['semaphore'] = array(
    'description' => 'Table for holding semaphores, locks, flags, etc. that cannot be stored as Drupal variables since they must not be cached.',
    'fields' => array(
      'name' => array(
        'description' => 'Primary Key: Unique name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => ''
      ),
      'value' => array(
        'description' => 'A value for the semaphore.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => ''
      ),
      'expire' => array(
        'description' => 'A Unix timestamp with microseconds indicating when the semaphore should expire.',
        'type' => 'float',
        'size' => 'big',
        'not null' => TRUE
      ),
    ),
    'indexes' => array(
      'value' => array('value'),
      'expire' => array('expire'),
    ),
    'primary key' => array('name'),
  );

  $schema['sequences'] = array(
    'description' => 'Stores IDs.',
    'fields' => array(
      'value' => array(
        'description' => 'The value of the sequence.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
     ),
    'primary key' => array('value'),
  );

  $schema['sessions'] = array(
    'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
    'fields' => array(
      'uid' => array(
        'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'sid' => array(
        'description' => "A session ID. The value is generated by Drupal's session handlers.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'ssid' => array(
        'description' => "Secure session ID. The value is generated by Drupal's session handlers.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'hostname' => array(
        'description' => 'The IP address that last used this session ID (sid).',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'timestamp' => array(
        '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,
      ),
      'session' => array(
        'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
    ),
    'primary key' => array(
      'sid',
      'ssid',
    ),
    'indexes' => array(
      'timestamp' => array('timestamp'),
      'uid' => array('uid'),
      'ssid' => array('ssid'),
    ),
    'foreign keys' => array(
      'session_user' => array(
        'table' => 'users',
        'columns' => array('uid' => 'uid'),
      ),
    ),
  );

  $schema['url_alias'] = array(
    'description' => 'A list of URL aliases for Drupal paths; a user may visit either the source or destination path.',
    'fields' => array(
      'pid' => array(
        'description' => 'A unique path alias identifier.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'source' => array(
        'description' => 'The Drupal path this alias is for; e.g. node/12.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'alias' => array(
        'description' => 'The alias for this path; e.g. title-of-the-story.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => "The language code this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array('pid'),
    'indexes' => array(
      'alias_langcode_pid' => array('alias', 'langcode', 'pid'),
      'source_langcode_pid' => array('source', 'langcode', 'pid'),
    ),
  );

  $schema['config_snapshot'] = array(
    'description' => 'Stores a snapshot of the last imported configuration.',
    'fields' => array(
      'name' => array(
        'description' => 'The identifier for the config object (the name of the file, minus the file extension).',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => 'The raw data for this configuration object.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ),
    ),
    'primary key' => array('name'),
  );

  return $schema;
}

/**
 * The cache schema corresponding to Drupal 8.0.
 *
 * Helper function to add cache tables in the Drupal 7 to 8 upgrade path
 * without relying on system_schema(), which may change with future updates.
 */
function system_schema_cache_8007() {
  return array(
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
    'fields' => array(
      'cid' => array(
        'description' => 'Primary Key: Unique cache ID.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => 'A collection of data to cache.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'expire' => array(
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'serialized' => array(
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
      'tags' => array(
        'description' => 'Space-separated list of cache tags for this entry.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'checksum_invalidations' => array(
        'description' => 'The tag invalidation sum when this entry was saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'checksum_deletions' => array(
        'description' => 'The tag deletion sum when this entry was saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'expire' => array('expire'),
    ),
    'primary key' => array('cid'),
  );
}

// Updates for core.

function system_update_last_removed() {
  return 7069;
}

//Do not copy @defgroup to other files. Use @addtogroup instead.
/**
 * @defgroup config_upgrade Configuration system upgrade functions
 * @{
 * Module update functions that
 * - update variables prior to configuration system conversions
 * - convert variables to the new configuration system
 * - update configuration system values after conversion
 *
 * @} End of "defgroup config_upgrade".
 */

/**
 * @defgroup updates-7.x-to-8.x Updates from 7.x to 8.x
 * @{
 * Update functions from 7.x to 8.x.
 */

/**
 * Move from the Garland theme.
 */
function system_update_8001() {
  $themes = array('theme_default', 'maintenance_theme', 'admin_theme');
  foreach ($themes as $theme) {
    if (update_variable_get($theme) == 'garland') {
      update_variable_set($theme, 'bartik');
    }
  }
}

/**
 * Set 'node' as front page path and Bartik as default theme if it implicitly was before.
 *
 * Node module became optional. The default front page path was changed to
 * 'user'. Since 'node' was the implicit default front page path previously and
 * may not have been explicitly configured as such, this update ensures that the
 * old implicit default is still the default.
 *
 * @see http://drupal.org/node/375397
 *
 * The default theme for Drupal core was changed from Bartik to Stark.
 * Installation profiles (including Standard and Minimal) were changed to
 * explicitly configure Bartik as default theme. Since Bartik was the default
 * theme by default and may not have been explicitly configured as such
 * previously, this update ensures that the implicit Bartik default is still the
 * default.
 *
 * @see http://drupal.org/node/1181776
 *
 * @ingroup config_upgrade
 */
function system_update_8002() {
  $front_page = update_variable_get('site_frontpage');
  if (!isset($front_page)) {
    update_variable_set('site_frontpage', 'node');
  }
  $theme = update_variable_get('theme_default');
  if (!isset($theme)) {
    update_variable_set('theme_default', 'bartik');
  }
}

/**
 * Creates {cache_config} cache table for the new configuration system.
 */
function system_update_8003() {
  // Moved to update_prepare_d8_bootstrap.
}

/**
 * Adds {file_managed}.langcode field.
 *
 * @see http://drupal.org/node/1454538
 */
function system_update_8004() {
  $langcode_field = array(
    'description' => 'The {language}.langcode of this file.',
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
  );

  // If a Drupal 7 contrib module already added a langcode field to support
  // internationalization, keep it, but standardize the specification.
  // Otherwise, add the field.
  if (db_field_exists('file_managed', 'langcode')) {
    // According to the documentation of db_change_field(), indices using the
    // field should be dropped first; if the contrib module created any indices,
    // it is its responsibility to drop them in an update function that runs
    // before this one, which it can enforce via hook_update_dependencies().
    db_change_field('file_managed', 'langcode', 'langcode', $langcode_field);
  }
  else {
    // Files can be language-specific (e.g., a scanned document) or not (e.g.,
    // a photograph). For a site being updated, Drupal does not have a way to
    // determine which existing files are language-specific and in what
    // language. Our best guess is to set all of them to LANGUAGE_NOT_SPECIFIED.
    $langcode_field['initial'] = LANGUAGE_NOT_SPECIFIED;
    db_add_field('file_managed', 'langcode', $langcode_field);
  }
}

 /**
 * Remove the obsolete {session}.cache column.
 */
function system_update_8005() {
  db_drop_field('session', 'cache');
}

 /**
 * Adds the {cache_tags} table.
 */
function system_update_8006() {
  // Moved to update_prepare_d8_bootstrap.
}

/**
 * Modifies existing cache tables, adding support for cache tags.
 */
function system_update_8007() {
  // Moved to update_prepare_d8_bootstrap.
}

/**
 * Remove the 'clean_url' configuration variable.
 */
function system_update_8008() {
  update_variable_del('clean_url');
}

/**
 * Moves cron system settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8009() {
  update_variables_to_config('system.cron', array(
    'cron_safe_threshold' => 'threshold.autorun',
    'cron_threshold_warning' => 'threshold.requirements_warning',
    'cron_threshold_error' => 'threshold.requirements_error',
  ));
}

/**
 * Moves RSS system settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8010() {
  update_variables_to_config('system.rss', array(
    'feed_description' => 'channel.description',
    'feed_default_items' => 'items.limit',
    'feed_item_length' => 'items.view_mode',
  ));
}

/**
 * Update the module and base fields for the blog node type.
 */
function system_update_8011() {
  db_update('node_type')
    ->fields(array(
      'module' => 'node',
      'base' => 'node_content',
    ))
    ->condition('module', 'blog')
    ->execute();
}

/**
 * Moves site system settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8012() {
  update_variables_to_config('system.site', array(
    'site_name' => 'name',
    'site_mail' => 'mail',
    'site_slogan' => 'slogan',
    'site_frontpage' => 'page.front',
    'site_403' => 'page.403',
    'site_404' => 'page.404',
    'drupal_weight_select_max' => 'weight_select_max',
  ));
}

/**
 * Add description_callback and description_arguments fields to {menu_router}.
 */
function system_update_8013() {
  if (!db_field_exists('menu_router', 'description_callback')) {
    $spec = array(
      'description' => 'A function which will alter the description. Defaults to t().',
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
      'default' => '',
    );
    db_add_field('menu_router', 'description_callback', $spec);
  }
  if (!db_field_exists('menu_router', 'description_arguments')) {
    $spec = array(
      'description' => 'A serialized array of arguments for the description callback. If empty, the description will be used as the sole argument for the description callback.',
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
      'default' => '',
    );
    db_add_field('menu_router', 'description_arguments', $spec);
  }
}

/**
 * Moves system logging settings from variables to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8014() {
  // Not using update_variables_to_config(), since the only value is
  // 'error_level', which needs to be mapped to a new value.
  $config = config('system.logging');
  $error_level = db_query("SELECT value FROM {variable} WHERE name = 'error_level'")->fetchField();
  if ($error_level !== FALSE) {
    $error_level = unserialize($error_level);
    $map = array(
      '0' => 'hide',
      '1' => 'some',
      '2' => 'all',
      '3' => 'verbose',
    );
    // Update error_level value to a string identifier.
    $config->set('error_level', $map[$error_level]);
    // Delete the migrated variable.
    db_delete('variable')->condition('name', 'error_level')->execute();
  }
  else {
    // Set error_level to the default value.
    $config->set('error_level', 'all');
  }
  $config->save();
}

/**
 * Create a UUID column for managed files.
 */
function system_update_8015() {
  $spec = array(
    'description' => 'Unique Key: Universally unique identifier for this entity.',
    'type' => 'varchar',
    'length' => 128,
    'not null' => FALSE,
  );
  $keys = array(
    'unique keys' => array(
      'uuid' => array('uuid'),
    ),
  );
  // Account for sites having the contributed UUID module installed.
  if (db_field_exists('file_managed', 'uuid')) {
    db_change_field('file_managed', 'uuid', 'uuid', $spec, $keys);
  }
  else {
    db_add_field('file_managed', 'uuid', $spec, $keys);
  }
}

/**
 * Move the system maintenance settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8016() {
  update_variables_to_config('system.maintenance', array(
    'maintenance_mode' => 'enabled',
    'maintenance_mode_message' => 'message',
  ));
}

/**
 * Moves system performance settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8017() {
  update_variables_to_config('system.performance', array(
    'cache' => 'cache.page.use_internal',
    'page_cache_maximum_age' => 'cache.page.max_age',
    'page_compression' => 'response.gzip',
    'preprocess_css' => 'css.preprocess',
    'preprocess_js' => 'js.preprocess',
    'stale_file_threshold' => 'stale_file_threshold',
  ));
}

/**
 * Remove the registry tables.
 */
function system_update_8019() {
  db_drop_table('registry');
  db_drop_table('registry_file');
}

/**
 * Conditionally enable the new Ban module.
 */
function system_update_8020() {
  $blocked_ips_exists = db_query_range('SELECT 1 FROM {blocked_ips}', 0, 1)->fetchField();
  if ($blocked_ips_exists) {
    // Rename the permission name.
    db_update('role_permission')
      ->fields(array(
        'permission' => 'ban IP addresses',
        'module' => 'ban',
      ))
      ->condition('permission', 'block IP addresses')
      ->execute();
    // Rename {blocked_ips} table into {ban_ip}.
    db_rename_table('blocked_ips', 'ban_ip');
    // Remove all references to the removed action callback.
    db_delete('actions')
      ->condition('callback', 'system_block_ip_action')
      ->execute();
    db_delete('actions')
      ->condition('aid', 'system_block_ip_action')
      ->execute();
    // Enable the new Ban module.
    update_module_enable(array('ban'));
  }
  else {
    // Drop old table.
    db_drop_table('blocked_ips');
  }
}

/**
 * Enable the Actions module.
 */
function system_update_8021() {
  // Enable the module without re-installing the schema.
  update_module_enable(array('action'));
  // Rename former System module actions.
  $map = array(
    'system_message_action' => 'action_message_action',
    'system_send_email_action' => 'action_send_email_action',
    'system_goto_action' => 'action_goto_action',
  );
  foreach ($map as $old => $new) {
    // Rename all references to the action callback.
    db_update('actions')
      ->fields(array('callback' => $new))
      ->condition('callback', $old)
      ->execute();
    // Rename the action's aid.
    db_update('actions')
      ->fields(array('aid' => $new))
      ->condition('aid', $old)
      ->execute();
  }
}

/**
 * Create the new routing table.
 */
function system_update_8022() {

  $tables['router'] = array(
    'description' => 'Maps paths to various callbacks (access, page and title)',
    'fields' => array(
      'name' => array(
        'description' => 'Primary Key: Machine name of this route',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'pattern' => array(
        'description' => 'The path pattern for this URI',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'pattern_outline' => array(
        'description' => 'The pattern',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'route_set' => array(
        'description' => 'The route set grouping to which a route belongs.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'fit' => array(
        'description' => 'A numeric representation of how specific the path is.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'route' => array(
        'description' => 'A serialized Route object',
        'type' => 'text',
      ),
      'number_parts' => array(
        'description' => 'Number of parts in this router path.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'small',
      ),
    ),
    'indexes' => array(
      'fit' => array('fit'),
      'pattern_outline' => array('pattern_outline'),
      'route_set' => array('route_set'),
    ),
    'primary key' => array('name'),
  );

  $schema = Database::getConnection()->schema();

  $schema->dropTable('router');

  $schema->createTable('router', $tables['router']);
}

/**
 * Create the 'key_value_expire' table.
 */
function system_update_8023() {
  // Moved to update_fix_d8_requirements() as it is required early.
}

/**
 * Generate a UUID for all files.
 */
function system_update_8024(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['last'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(fid) FROM {file_managed} WHERE uuid IS NULL')->fetchField();
  }

  $fids = db_query_range('SELECT fid FROM {file_managed} WHERE fid > :fid AND uuid IS NULL ORDER BY fid ASC', 0, 10, array(':fid' => $sandbox['last']))->fetchCol();
  update_add_uuids($sandbox, 'file_managed', 'fid', $fids);

  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}

/**
 * Remove {system} table.
 */
function system_update_8025() {
  db_drop_table('system');
}

/**
 * Cleans up javascript_parsed variable.
 *
 * @ingroup system_upgrade
 */
function system_update_8027() {
  update_variable_del('javascript_parsed');
}

/**
 * Remove the 'menu_masks' configuration variable.
 */
function system_update_8028() {
  // No upgrade path needed since the menu router will be rebuilt during the
  // Drupal 7 to Drupal 8 upgrade.
  update_variable_del('menu_masks');
}

/**
 * Convert path_alias_whitelist variable to state API.
 *
 * @ingroup state_upgrade
 */
function system_update_8029() {
  if ($value = update_variable_get('path_alias_whitelist', FALSE)) {
    state()->set('system.path_alias_whitelist', $value);
  }
  update_variable_del('path_alias_whitelist');
}

 /**
 * Moves authorize system settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8030() {
  update_variables_to_config('system.authorize', array(
    'authorize_filetransfer_default' => 'filetransfer_default',
  ));
}

/**
 * Rename default menu names.
 */
function system_update_8031() {
  $map = array(
    'navigation' => 'tools',
    'management' => 'admin',
    'user-menu' => 'account',
    'main-menu' => 'main',
  );
  foreach ($map as $old => $new) {
    db_update('menu_links')
      ->condition('menu_name', $old)
      ->fields(array('menu_name' => $new))
      ->execute();
  }
}

/**
 * Removes the drupal_js_cache_files variable.
 *
 * @ingroup config_upgrade
 */
function system_update_8032() {
  update_variable_del('drupal_js_cache_files');
}

/**
 * Converts active_menus_default variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8033() {
  update_variables_to_config('system.menu', array(
    'active_menus_default' => 'active_menus_default'
  ));
}

/**
 * Moves cron last run time and cron key from variable to state.
 *
 * @ingroup config_upgrade
 */
function system_update_8034() {
  update_variables_to_state(array(
    'cron_last' => 'system.cron_last',
    'cron_key' => 'system.cron_key',
    ));
}

/**
 * Moves filter_allowed_protocols variable to config.
 *
 * This config is provided now by the system module because it is used by
 * drupal_strip_dangerous_protocols() and must to be available before the filter
 * module be installed.
 *
 * @ingroup config_upgrade
 */
function system_update_8035() {
  update_variables_to_config('system.filter', array(
    'filter_allowed_protocols' => 'protocols',
  ));
}

/**
 * Move the admin_compact_mode setting from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8036() {
  update_variables_to_config('system.site', array(
    'admin_compact_mode' => 'admin_compact_mode',
  ));
}

/**
 * Remove the 'password_count_log2' variable.
 *
 * @ingroup config_upgrade
 */
function system_update_8037() {
  update_variable_del('password_count_log2');
}

/**
 * Moves site system regional settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8038() {
  update_variables_to_config('system.date', array(
    'site_default_country' => 'country.default',
    'date_first_day' => 'first_day',
    'date_default_timezone' => 'timezone.default',
  ));
  update_variables_to_config('system.timezone', array(
    'date_default_timezone' => 'default',
    'configurable_timezones' => 'user.configurable',
    'empty_timezone_message' => 'user.warn',
    'user_default_timezone' => 'user.default',
  ));
}

/**
 * Converts css and js gzip compression variables to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8039() {
  $variable_map = array(
    'css_gzip_compression' => 'css.gzip',
    'js_gzip_compression' => 'js.gzip'
  );
  update_variables_to_config('system.performance', $variable_map);
}

/**
 * Moves action_max_stack from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8040() {
  update_variables_to_config('action.settings', array(
    'actions_max_stack' => 'recursion_limit',
  ));
}

/**
 * Converts admin_theme variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8041() {
  update_variables_to_config('system.theme', array(
    'admin_theme' => 'admin',
    'theme_default' => 'default'
  ));
}

/**
 * Enable the new Entity module.
 */
function system_update_8042() {
  update_module_enable(array('entity'));
}

/**
 * Moves system theme settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8043() {
  update_variables_to_config('system.performance', array(
    'theme_link' => 'theme_link',
  ));
}

/**
 * Moves system fast 404 settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8044() {
  update_variables_to_config('system.performance', array(
    'fast_404_html' => 'fast_404.html',
    'fast_404_paths' => 'fast_404.paths',
    'fast_404_paths_exclude' => 'fast_404.exclude_paths',
  ));
}

/**
 * Converts existing date formats to the new config system.
 */
function system_update_8045() {
  // Get the date config object.
  $config = config('system.date');

  // Fetch all date types from {date_format_type}.
  $date_formats = db_query('SELECT * FROM {date_format_type}')->fetchAllAssoc('type', PDO::FETCH_ASSOC);
  if (!empty($date_formats)) {
    foreach ($date_formats as $type => $format) {
      // Set name and locked properties.
      $config->set("formats.{$type}.name", $format['title']);
      $config->set("formats.{$type}.locked", $format['locked']);

      // Get the default date format for this type.
      $variable_name = 'date_format_' . $type;
      $default_format = update_variable_get($variable_name, NULL);
      if ($default_format) {
        // In Drupal 7 we only used PHP date types.
        $config->set("formats.{$type}.pattern.php", $default_format);

        // Delete the migrated variables.
        update_variable_del($variable_name);
      }
    }

    // Save the date configuration object.
    $config->save();
  }
}

/**
 * Enable Views if the node listing is set as the frontpage.
 */
function system_update_8046() {
  $front_page = config('system.site')->get('page.front');
  if (!isset($front_page) || $front_page == 'node') {
    update_module_enable(array('views'));

    // Register views to the container, so views can use it's services.
    $module_list = drupal_container()->getParameter('container.modules');
    drupal_load('module', 'views');

    drupal_container()->get('kernel')->updateModules(array_keys($module_list), array('views' => 'core/modules/views/views.module'));

    // This does not fire a hook just calls views.
    config_install_default_config('module', 'views');
    // This imports the node frontpage view.
    config_install_default_config('module', 'node');
  }
}

/**
 * Moves site system settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8047() {
  update_variables_to_config('system.file', array(
    'allow_insecure_uploads' => 'allow_insecure_uploads',
    'file_default_scheme' => 'default_scheme',
    'file_chmod_directory' => 'chmod.directory',
    'file_chmod_file' => 'chmod.file',
    'file_private_path' => 'path.private',
    'file_temporary_path' => 'path.temporary',
  ));
}

/**
 * Enable the new Menu link module.
 *
 * Creates the langcode and UUID columns for menu links.
 */
function system_update_8048() {
  // Enable the module without re-installing the schema.
  update_module_enable(array('menu_link'));

  // Add the langcode column if it doesn't exist.
  if (!db_field_exists('menu_inks', 'langcode')) {
    $column = array(
      'description' => 'The {language}.langcode of this entity.',
      'type' => 'varchar',
      'length' => 12,
      'not null' => TRUE,
      'default' => '',
    );
    db_add_field('menu_links', 'langcode', $column);
  }

  // Add the UUID column.
  $column = array(
    'description' => 'Unique Key: Universally unique identifier for this entity.',
    'type' => 'varchar',
    'length' => 128,
    'not null' => FALSE,
  );
  $keys = array(
    'unique keys' => array(
      'uuid' => array('uuid'),
    ),
  );
  db_add_field('menu_links', 'uuid', $column, $keys);
}

/**
 * Create the 'config_snapshot' table.
 */
function system_update_8049() {
  $table = array(
    'description' => 'Stores a snapshot of the last imported configuration.',
    'fields' => array(
      'name' => array(
        'description' => 'The identifier for the config object (the name of the file, minus the file extension).',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => 'The raw data for this configuration object.',
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
      ),
    ),
    'primary key' => array('name'),
  );

  db_create_table('config_snapshot', $table);
}

/**
 * Converts mail settings to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8050() {
  // Update any mail interfaces to their Drupal 8 equivalents.
  $old_mail_system_settings = update_variable_get('mail_system');

  if ($old_mail_system_settings) {
    $new_mail_system_settings = array();

    foreach ($old_mail_system_settings as $key => $mailer_class) {
      // Update old class name to PSR-0.
      if ($mailer_class == 'DefaultMailSystem') {
        $mailer_class = 'Drupal\Core\Mail\PhpMail';
      }
      // New default key.
      if ($key == 'default-system') {
        $new_mail_system_settings['default'] = $mailer_class;
        unset($old_mail_system_settings[$key]);
      }
    }
    if (count($old_mail_system_settings)) {
      // Warn about non-core classes which may need to be updated.
      drupal_set_message(format_string('The following mail backends need to be re-configured: @list.', array('@list' => implode(', ', $old_mail_system_settings))), 'warning');
    }

    $new_mail_system_settings += $old_mail_system_settings;
    // Save the updated variable, and let update_variables_to_config convert it.
    if ($new_mail_system_settings) {
      update_variable_set('mail_system', $new_mail_system_settings);
    }
  }
  update_variables_to_config('system.mail', array(
    'mail_system' => 'interface',
  ));
}

/**
 * Adds route_name column to the menu_links table.
 */
function system_update_8051() {
  $spec = array(
    'description' => 'The machine name of a defined Symfony Route this menu item represents.',
    'type' => 'varchar',
    'length' => 255,
  );

  db_add_field('menu_links', 'route_name', $spec);
}

/**
 * Moves image toolkit settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function system_update_8052() {
  update_variables_to_config('system.image', array(
    'image_toolkit' => 'toolkit',
  ));
  update_variables_to_config('system.image.gd', array(
    'image_jpeg_quality' => 'jpeg_quality',
  ));
}

/**
 * @} End of "defgroup updates-7.x-to-8.x".
 * The next series of updates should start at 9000.
 */