system.install 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the system module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function system_requirements($phase) {
  10. global $base_url;
  11. $requirements = array();
  12. // Ensure translations don't break during installation.
  13. $t = get_t();
  14. // Report Drupal version
  15. if ($phase == 'runtime') {
  16. $requirements['drupal'] = array(
  17. 'title' => $t('Drupal'),
  18. 'value' => VERSION,
  19. 'severity' => REQUIREMENT_INFO,
  20. 'weight' => -10,
  21. );
  22. // Display the currently active installation profile, if the site
  23. // is not running the default installation profile.
  24. $profile = drupal_get_profile();
  25. if ($profile != 'standard') {
  26. $info = system_get_info('module', $profile);
  27. $requirements['install_profile'] = array(
  28. 'title' => $t('Install profile'),
  29. 'value' => $t('%profile_name (%profile-%version)', array(
  30. '%profile_name' => $info['name'],
  31. '%profile' => $profile,
  32. '%version' => $info['version']
  33. )),
  34. 'severity' => REQUIREMENT_INFO,
  35. 'weight' => -9
  36. );
  37. }
  38. }
  39. // Web server information.
  40. $software = $_SERVER['SERVER_SOFTWARE'];
  41. $requirements['webserver'] = array(
  42. 'title' => $t('Web server'),
  43. 'value' => $software,
  44. );
  45. // Test PHP version and show link to phpinfo() if it's available
  46. $phpversion = phpversion();
  47. if (function_exists('phpinfo')) {
  48. $requirements['php'] = array(
  49. 'title' => $t('PHP'),
  50. 'value' => ($phase == 'runtime') ? $phpversion .' ('. l($t('more information'), 'admin/reports/status/php') .')' : $phpversion,
  51. );
  52. }
  53. else {
  54. $requirements['php'] = array(
  55. 'title' => $t('PHP'),
  56. 'value' => $phpversion,
  57. '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')),
  58. 'severity' => REQUIREMENT_INFO,
  59. );
  60. }
  61. if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
  62. $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
  63. $requirements['php']['severity'] = REQUIREMENT_ERROR;
  64. // If PHP is old, it's not safe to continue with the requirements check.
  65. return $requirements;
  66. }
  67. // Check that htmlspecialchars() is secure if the site is running any PHP
  68. // version older than 5.2.5. We don't simply require 5.2.5, because Ubuntu
  69. // 8.04 ships with PHP 5.2.4, but includes the necessary security patch.
  70. elseif (version_compare($phpversion, '5.2.5') < 0 && strlen(@htmlspecialchars(chr(0xC0) . chr(0xAF), ENT_QUOTES, 'UTF-8'))) {
  71. $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP 5.2.5, or PHP @version with the htmlspecialchars security patch backported.', array('@version' => DRUPAL_MINIMUM_PHP));
  72. $requirements['php']['severity'] = REQUIREMENT_ERROR;
  73. // If PHP is old, it's not safe to continue with the requirements check.
  74. return $requirements;
  75. }
  76. // Test PHP register_globals setting.
  77. $requirements['php_register_globals'] = array(
  78. 'title' => $t('PHP register globals'),
  79. );
  80. $register_globals = trim(ini_get('register_globals'));
  81. // Unfortunately, ini_get() may return many different values, and we can't
  82. // be certain which values mean 'on', so we instead check for 'not off'
  83. // since we never want to tell the user that their site is secure
  84. // (register_globals off), when it is in fact on. We can only guarantee
  85. // register_globals is off if the value returned is 'off', '', or 0.
  86. if (!empty($register_globals) && strtolower($register_globals) != 'off') {
  87. $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="http://php.net/configuration.changes">how to change configuration settings</a>.');
  88. $requirements['php_register_globals']['severity'] = REQUIREMENT_ERROR;
  89. $requirements['php_register_globals']['value'] = $t("Enabled ('@value')", array('@value' => $register_globals));
  90. }
  91. else {
  92. $requirements['php_register_globals']['value'] = $t('Disabled');
  93. }
  94. // Test for PHP extensions.
  95. $requirements['php_extensions'] = array(
  96. 'title' => $t('PHP extensions'),
  97. );
  98. $missing_extensions = array();
  99. $required_extensions = array(
  100. 'date',
  101. 'dom',
  102. 'filter',
  103. 'gd',
  104. 'hash',
  105. 'json',
  106. 'pcre',
  107. 'pdo',
  108. 'session',
  109. 'SimpleXML',
  110. 'SPL',
  111. 'xml',
  112. );
  113. foreach ($required_extensions as $extension) {
  114. if (!extension_loaded($extension)) {
  115. $missing_extensions[] = $extension;
  116. }
  117. }
  118. if (!empty($missing_extensions)) {
  119. $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(
  120. '@system_requirements' => 'http://drupal.org/requirements',
  121. ));
  122. $description .= theme('item_list', array('items' => $missing_extensions));
  123. $requirements['php_extensions']['value'] = $t('Disabled');
  124. $requirements['php_extensions']['severity'] = REQUIREMENT_ERROR;
  125. $requirements['php_extensions']['description'] = $description;
  126. }
  127. else {
  128. $requirements['php_extensions']['value'] = $t('Enabled');
  129. }
  130. if ($phase == 'install' || $phase == 'update') {
  131. // Test for PDO (database).
  132. $requirements['database_extensions'] = array(
  133. 'title' => $t('Database support'),
  134. );
  135. // Make sure PDO is available.
  136. $database_ok = extension_loaded('pdo');
  137. if (!$database_ok) {
  138. $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(
  139. '@link' => 'http://drupal.org/requirements/pdo',
  140. ));
  141. }
  142. else {
  143. // Make sure at least one supported database driver exists.
  144. $drivers = drupal_detect_database_types();
  145. if (empty($drivers)) {
  146. $database_ok = FALSE;
  147. $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(
  148. '@drupal-databases' => 'https://www.drupal.org/requirements/database',
  149. ));
  150. }
  151. // Make sure the native PDO extension is available, not the older PEAR
  152. // version. (See install_verify_pdo() for details.)
  153. if (!defined('PDO::ATTR_DEFAULT_FETCH_MODE')) {
  154. $database_ok = FALSE;
  155. $pdo_message = $t('Your web server seems to have the wrong version of PDO installed. Drupal 7 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(
  156. '@link' => 'http://drupal.org/requirements/pdo#pecl',
  157. ));
  158. }
  159. }
  160. if (!$database_ok) {
  161. $requirements['database_extensions']['value'] = $t('Disabled');
  162. $requirements['database_extensions']['severity'] = REQUIREMENT_ERROR;
  163. $requirements['database_extensions']['description'] = $pdo_message;
  164. }
  165. else {
  166. $requirements['database_extensions']['value'] = $t('Enabled');
  167. }
  168. }
  169. else {
  170. // Database information.
  171. $class = 'DatabaseTasks_' . Database::getConnection()->driver();
  172. $tasks = new $class();
  173. $requirements['database_system'] = array(
  174. 'title' => $t('Database system'),
  175. 'value' => $tasks->name(),
  176. );
  177. $requirements['database_system_version'] = array(
  178. 'title' => $t('Database system version'),
  179. 'value' => Database::getConnection()->version(),
  180. );
  181. }
  182. // Test database-specific multi-byte UTF-8 related requirements.
  183. $charset_requirements = _system_check_db_utf8mb4_requirements($phase);
  184. if (!empty($charset_requirements)) {
  185. $requirements['database_charset'] = $charset_requirements;
  186. }
  187. // Test PHP memory_limit
  188. $memory_limit = ini_get('memory_limit');
  189. $requirements['php_memory_limit'] = array(
  190. 'title' => $t('PHP memory limit'),
  191. 'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
  192. );
  193. if (!drupal_check_memory_limit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
  194. $description = '';
  195. if ($phase == 'install') {
  196. $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));
  197. }
  198. elseif ($phase == 'update') {
  199. $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));
  200. }
  201. elseif ($phase == 'runtime') {
  202. $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));
  203. }
  204. if (!empty($description)) {
  205. if ($php_ini_path = get_cfg_var('cfg_file_path')) {
  206. $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));
  207. }
  208. else {
  209. $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
  210. }
  211. $requirements['php_memory_limit']['description'] = $description . ' ' . $t('See the <a href="@url">Drupal requirements</a> for more information.', array('@url' => 'http://drupal.org/requirements'));
  212. $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
  213. }
  214. }
  215. // Test settings.php file writability
  216. if ($phase == 'runtime') {
  217. $conf_dir = drupal_verify_install_file(conf_path(), FILE_NOT_WRITABLE, 'dir');
  218. $conf_file = drupal_verify_install_file(conf_path() . '/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE);
  219. if (!$conf_dir || !$conf_file) {
  220. $requirements['settings.php'] = array(
  221. 'value' => $t('Not protected'),
  222. 'severity' => REQUIREMENT_ERROR,
  223. 'description' => '',
  224. );
  225. if (!$conf_dir) {
  226. $requirements['settings.php']['description'] .= $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()));
  227. }
  228. if (!$conf_file) {
  229. $requirements['settings.php']['description'] .= $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' => conf_path() . '/settings.php'));
  230. }
  231. }
  232. else {
  233. $requirements['settings.php'] = array(
  234. 'value' => $t('Protected'),
  235. );
  236. }
  237. $requirements['settings.php']['title'] = $t('Configuration file');
  238. }
  239. // Test the contents of the .htaccess files.
  240. if ($phase == 'runtime') {
  241. // Try to write the .htaccess files first, to prevent false alarms in case
  242. // (for example) the /tmp directory was wiped.
  243. file_ensure_htaccess();
  244. $htaccess_files['public://.htaccess'] = array(
  245. 'title' => $t('Public files directory'),
  246. 'directory' => variable_get('file_public_path', conf_path() . '/files'),
  247. );
  248. if ($private_files_directory = variable_get('file_private_path')) {
  249. $htaccess_files['private://.htaccess'] = array(
  250. 'title' => $t('Private files directory'),
  251. 'directory' => $private_files_directory,
  252. );
  253. }
  254. $htaccess_files['temporary://.htaccess'] = array(
  255. 'title' => $t('Temporary files directory'),
  256. 'directory' => variable_get('file_temporary_path', file_directory_temp()),
  257. );
  258. foreach ($htaccess_files as $htaccess_file => $info) {
  259. // Check for the string which was added to the recommended .htaccess file
  260. // in the latest security update.
  261. if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
  262. $requirements[$htaccess_file] = array(
  263. 'title' => $info['title'],
  264. 'value' => $t('Not fully protected'),
  265. 'severity' => REQUIREMENT_ERROR,
  266. 'description' => $t('See <a href="@url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', array('@url' => 'http://drupal.org/SA-CORE-2013-003', '%directory' => $info['directory'])),
  267. );
  268. }
  269. }
  270. }
  271. // Report cron status.
  272. if ($phase == 'runtime') {
  273. // Cron warning threshold defaults to two days.
  274. $threshold_warning = variable_get('cron_threshold_warning', 172800);
  275. // Cron error threshold defaults to two weeks.
  276. $threshold_error = variable_get('cron_threshold_error', 1209600);
  277. // Cron configuration help text.
  278. $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'));
  279. // Determine when cron last ran.
  280. $cron_last = variable_get('cron_last');
  281. if (!is_numeric($cron_last)) {
  282. $cron_last = variable_get('install_time', 0);
  283. }
  284. // Determine severity based on time since cron last ran.
  285. $severity = REQUIREMENT_OK;
  286. if (REQUEST_TIME - $cron_last > $threshold_error) {
  287. $severity = REQUIREMENT_ERROR;
  288. }
  289. elseif (REQUEST_TIME - $cron_last > $threshold_warning) {
  290. $severity = REQUIREMENT_WARNING;
  291. }
  292. // Set summary and description based on values determined above.
  293. $summary = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last)));
  294. $description = '';
  295. if ($severity != REQUIREMENT_OK) {
  296. $description = $t('Cron has not run recently.') . ' ' . $help;
  297. }
  298. $description .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
  299. $description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => variable_get('cron_key', 'drupal'))))));
  300. $requirements['cron'] = array(
  301. 'title' => $t('Cron maintenance tasks'),
  302. 'severity' => $severity,
  303. 'value' => $summary,
  304. 'description' => $description
  305. );
  306. }
  307. // Test files directories.
  308. $directories = array(
  309. variable_get('file_public_path', conf_path() . '/files'),
  310. // By default no private files directory is configured. For private files
  311. // to be secure the admin needs to provide a path outside the webroot.
  312. variable_get('file_private_path', FALSE),
  313. );
  314. // Do not check for the temporary files directory during installation
  315. // unless it has been set in settings.php. In this case the user has
  316. // no alternative but to fix the directory if it is not writable.
  317. if ($phase == 'install') {
  318. $directories[] = variable_get('file_temporary_path', FALSE);
  319. }
  320. else {
  321. $directories[] = variable_get('file_temporary_path', file_directory_temp());
  322. }
  323. $requirements['file system'] = array(
  324. 'title' => $t('File system'),
  325. );
  326. $error = '';
  327. // For installer, create the directories if possible.
  328. foreach ($directories as $directory) {
  329. if (!$directory) {
  330. continue;
  331. }
  332. if ($phase == 'install') {
  333. file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
  334. }
  335. $is_writable = is_writable($directory);
  336. $is_directory = is_dir($directory);
  337. if (!$is_writable || !$is_directory) {
  338. $description = '';
  339. $requirements['file system']['value'] = $t('Not writable');
  340. if (!$is_directory) {
  341. $error .= $t('The directory %directory does not exist.', array('%directory' => $directory)) . ' ';
  342. }
  343. else {
  344. $error .= $t('The directory %directory is not writable.', array('%directory' => $directory)) . ' ';
  345. }
  346. // The files directory requirement check is done only during install and runtime.
  347. if ($phase == 'runtime') {
  348. $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')));
  349. }
  350. elseif ($phase == 'install') {
  351. // For the installer UI, we need different wording. 'value' will
  352. // be treated as version, so provide none there.
  353. $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'));
  354. $requirements['file system']['value'] = '';
  355. }
  356. if (!empty($description)) {
  357. $requirements['file system']['description'] = $description;
  358. $requirements['file system']['severity'] = REQUIREMENT_ERROR;
  359. }
  360. }
  361. else {
  362. if (file_default_scheme() == 'public') {
  363. $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)');
  364. }
  365. else {
  366. $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)');
  367. }
  368. }
  369. }
  370. // See if updates are available in update.php.
  371. if ($phase == 'runtime') {
  372. $requirements['update'] = array(
  373. 'title' => $t('Database updates'),
  374. 'severity' => REQUIREMENT_OK,
  375. 'value' => $t('Up to date'),
  376. );
  377. // Check installed modules.
  378. foreach (module_list() as $module) {
  379. $updates = drupal_get_schema_versions($module);
  380. if ($updates !== FALSE) {
  381. $default = drupal_get_installed_schema_version($module);
  382. if (max($updates) > $default) {
  383. $requirements['update']['severity'] = REQUIREMENT_ERROR;
  384. $requirements['update']['value'] = $t('Out of date');
  385. $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() . 'update.php'));
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. // Verify the update.php access setting
  392. if ($phase == 'runtime') {
  393. if (!empty($GLOBALS['update_free_access'])) {
  394. $requirements['update access'] = array(
  395. 'value' => $t('Not protected'),
  396. 'severity' => REQUIREMENT_ERROR,
  397. 'description' => $t('The update.php script is accessible to everyone without authentication check, which is a security risk. You must change the $update_free_access value in your settings.php back to FALSE.'),
  398. );
  399. }
  400. else {
  401. $requirements['update access'] = array(
  402. 'value' => $t('Protected'),
  403. );
  404. }
  405. $requirements['update access']['title'] = $t('Access to update.php');
  406. }
  407. // Display an error if a newly introduced dependency in a module is not resolved.
  408. if ($phase == 'update') {
  409. $profile = drupal_get_profile();
  410. $files = system_rebuild_module_data();
  411. foreach ($files as $module => $file) {
  412. // Ignore disabled modules and installation profiles.
  413. if (!$file->status || $module == $profile) {
  414. continue;
  415. }
  416. // Check the module's PHP version.
  417. $name = $file->info['name'];
  418. $php = $file->info['php'];
  419. if (version_compare($php, PHP_VERSION, '>')) {
  420. $requirements['php']['description'] .= $t('@name requires at least PHP @version.', array('@name' => $name, '@version' => $php));
  421. $requirements['php']['severity'] = REQUIREMENT_ERROR;
  422. }
  423. // Check the module's required modules.
  424. foreach ($file->requires as $requirement) {
  425. $required_module = $requirement['name'];
  426. // Check if the module exists.
  427. if (!isset($files[$required_module])) {
  428. $requirements["$module-$required_module"] = array(
  429. 'title' => $t('Unresolved dependency'),
  430. 'description' => $t('@name requires this module.', array('@name' => $name)),
  431. 'value' => t('@required_name (Missing)', array('@required_name' => $required_module)),
  432. 'severity' => REQUIREMENT_ERROR,
  433. );
  434. continue;
  435. }
  436. // Check for an incompatible version.
  437. $required_file = $files[$required_module];
  438. $required_name = $required_file->info['name'];
  439. $version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $required_file->info['version']);
  440. $compatibility = drupal_check_incompatibility($requirement, $version);
  441. if ($compatibility) {
  442. $compatibility = rtrim(substr($compatibility, 2), ')');
  443. $requirements["$module-$required_module"] = array(
  444. 'title' => $t('Unresolved dependency'),
  445. 'description' => $t('@name requires this module and version. Currently using @required_name version @version', array('@name' => $name, '@required_name' => $required_name, '@version' => $version)),
  446. 'value' => t('@required_name (Version @compatibility required)', array('@required_name' => $required_name, '@compatibility' => $compatibility)),
  447. 'severity' => REQUIREMENT_ERROR,
  448. );
  449. continue;
  450. }
  451. }
  452. }
  453. }
  454. // Test Unicode library
  455. include_once DRUPAL_ROOT . '/includes/unicode.inc';
  456. $requirements = array_merge($requirements, unicode_requirements());
  457. if ($phase == 'runtime') {
  458. // Check for update status module.
  459. if (!module_exists('update')) {
  460. $requirements['update status'] = array(
  461. 'value' => $t('Not enabled'),
  462. 'severity' => REQUIREMENT_WARNING,
  463. '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'))),
  464. );
  465. }
  466. else {
  467. $requirements['update status'] = array(
  468. 'value' => $t('Enabled'),
  469. );
  470. }
  471. $requirements['update status']['title'] = $t('Update notifications');
  472. // Check that Drupal can issue HTTP requests.
  473. if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
  474. $requirements['http requests'] = array(
  475. 'title' => $t('HTTP request status'),
  476. 'value' => $t('Fails'),
  477. 'severity' => REQUIREMENT_ERROR,
  478. 'description' => $t('Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services. If you are certain that Drupal can access web pages but you are still seeing this message, you may add <code>$conf[\'drupal_http_request_fails\'] = FALSE;</code> to the bottom of your settings.php file.'),
  479. );
  480. }
  481. }
  482. return $requirements;
  483. }
  484. /**
  485. * Checks whether the requirements for multi-byte UTF-8 support are met.
  486. *
  487. * @param string $phase
  488. * The hook_requirements() stage.
  489. *
  490. * @return array
  491. * A requirements array with the result of the charset check.
  492. */
  493. function _system_check_db_utf8mb4_requirements($phase) {
  494. global $install_state;
  495. // In the requirements check of the installer, skip the utf8mb4 check unless
  496. // the database connection info has been preconfigured by hand with valid
  497. // information before running the installer, as otherwise we cannot get a
  498. // valid database connection object.
  499. if (isset($install_state['settings_verified']) && !$install_state['settings_verified']) {
  500. return array();
  501. }
  502. $connection = Database::getConnection();
  503. $t = get_t();
  504. $requirements['title'] = $t('Database 4 byte UTF-8 support');
  505. $utf8mb4_configurable = $connection->utf8mb4IsConfigurable();
  506. $utf8mb4_active = $connection->utf8mb4IsActive();
  507. $utf8mb4_supported = $connection->utf8mb4IsSupported();
  508. $driver = $connection->driver();
  509. $documentation_url = 'https://www.drupal.org/node/2754539';
  510. if ($utf8mb4_active) {
  511. if ($utf8mb4_supported) {
  512. if ($phase != 'install' && $utf8mb4_configurable && !variable_get('drupal_all_databases_are_utf8mb4', FALSE)) {
  513. // Supported, active, and configurable, but not all database tables
  514. // have been converted yet.
  515. $requirements['value'] = $t('Enabled, but database tables need conversion');
  516. $requirements['description'] = $t('Please convert all database tables to utf8mb4 prior to enabling it in settings.php. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@url' => $documentation_url));
  517. $requirements['severity'] = REQUIREMENT_ERROR;
  518. }
  519. else {
  520. // Supported, active.
  521. $requirements['value'] = $t('Enabled');
  522. $requirements['description'] = $t('4 byte UTF-8 for @driver is enabled.', array('@driver' => $driver));
  523. $requirements['severity'] = REQUIREMENT_OK;
  524. }
  525. }
  526. else {
  527. // Not supported, active.
  528. $requirements['value'] = $t('Not supported');
  529. $requirements['description'] = $t('4 byte UTF-8 for @driver is activated, but not supported on your system. Please turn this off in settings.php, or ensure that all database-related requirements are met. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@driver' => $driver, '@url' => $documentation_url));
  530. $requirements['severity'] = REQUIREMENT_ERROR;
  531. }
  532. }
  533. else {
  534. if ($utf8mb4_supported) {
  535. // Supported, not active.
  536. $requirements['value'] = $t('Not enabled');
  537. $requirements['description'] = $t('4 byte UTF-8 for @driver is not activated, but it is supported on your system. It is recommended that you enable this to allow 4-byte UTF-8 input such as emojis, Asian symbols and mathematical symbols to be stored correctly. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@driver' => $driver, '@url' => $documentation_url));
  538. $requirements['severity'] = REQUIREMENT_INFO;
  539. }
  540. else {
  541. // Not supported, not active.
  542. $requirements['value'] = $t('Disabled');
  543. $requirements['description'] = $t('4 byte UTF-8 for @driver is disabled. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@driver' => $driver, '@url' => $documentation_url));
  544. $requirements['severity'] = REQUIREMENT_INFO;
  545. }
  546. }
  547. return $requirements;
  548. }
  549. /**
  550. * Implements hook_install().
  551. */
  552. function system_install() {
  553. // Create tables.
  554. drupal_install_schema('system');
  555. $versions = drupal_get_schema_versions('system');
  556. $version = $versions ? max($versions) : SCHEMA_INSTALLED;
  557. drupal_set_installed_schema_version('system', $version);
  558. // Clear out module list and hook implementation statics before calling
  559. // system_rebuild_theme_data().
  560. module_list(TRUE);
  561. module_implements('', FALSE, TRUE);
  562. // Ensure the schema versions are not based on a previous module list.
  563. drupal_static_reset('drupal_get_schema_versions');
  564. // Load system theme data appropriately.
  565. system_rebuild_theme_data();
  566. // Enable the default theme.
  567. variable_set('theme_default', 'bartik');
  568. db_update('system')
  569. ->fields(array('status' => 1))
  570. ->condition('type', 'theme')
  571. ->condition('name', 'bartik')
  572. ->execute();
  573. // Populate the cron key variable.
  574. $cron_key = drupal_random_key();
  575. variable_set('cron_key', $cron_key);
  576. }
  577. /**
  578. * Implements hook_schema().
  579. */
  580. function system_schema() {
  581. // NOTE: {variable} needs to be created before all other tables, as
  582. // some database drivers, e.g. Oracle and DB2, will require variable_get()
  583. // and variable_set() for overcoming some database specific limitations.
  584. $schema['variable'] = array(
  585. '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.',
  586. 'fields' => array(
  587. 'name' => array(
  588. 'description' => 'The name of the variable.',
  589. 'type' => 'varchar',
  590. 'length' => 128,
  591. 'not null' => TRUE,
  592. 'default' => '',
  593. ),
  594. 'value' => array(
  595. 'description' => 'The value of the variable.',
  596. 'type' => 'blob',
  597. 'not null' => TRUE,
  598. 'size' => 'big',
  599. 'translatable' => TRUE,
  600. ),
  601. ),
  602. 'primary key' => array('name'),
  603. );
  604. $schema['actions'] = array(
  605. 'description' => 'Stores action information.',
  606. 'fields' => array(
  607. 'aid' => array(
  608. 'description' => 'Primary Key: Unique actions ID.',
  609. 'type' => 'varchar',
  610. 'length' => 255,
  611. 'not null' => TRUE,
  612. 'default' => '0',
  613. ),
  614. 'type' => array(
  615. 'description' => 'The object that that action acts on (node, user, comment, system or custom types.)',
  616. 'type' => 'varchar',
  617. 'length' => 32,
  618. 'not null' => TRUE,
  619. 'default' => '',
  620. ),
  621. 'callback' => array(
  622. 'description' => 'The callback function that executes when the action runs.',
  623. 'type' => 'varchar',
  624. 'length' => 255,
  625. 'not null' => TRUE,
  626. 'default' => '',
  627. ),
  628. 'parameters' => array(
  629. 'description' => 'Parameters to be passed to the callback function.',
  630. 'type' => 'blob',
  631. 'not null' => TRUE,
  632. 'size' => 'big',
  633. ),
  634. 'label' => array(
  635. 'description' => 'Label of the action.',
  636. 'type' => 'varchar',
  637. 'length' => 255,
  638. 'not null' => TRUE,
  639. 'default' => '0',
  640. ),
  641. ),
  642. 'primary key' => array('aid'),
  643. );
  644. $schema['batch'] = array(
  645. 'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
  646. 'fields' => array(
  647. 'bid' => array(
  648. 'description' => 'Primary Key: Unique batch ID.',
  649. // This is not a serial column, to allow both progressive and
  650. // non-progressive batches. See batch_process().
  651. 'type' => 'int',
  652. 'unsigned' => TRUE,
  653. 'not null' => TRUE,
  654. ),
  655. 'token' => array(
  656. '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.",
  657. 'type' => 'varchar',
  658. 'length' => 64,
  659. 'not null' => TRUE,
  660. ),
  661. 'timestamp' => array(
  662. 'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.',
  663. 'type' => 'int',
  664. 'not null' => TRUE,
  665. ),
  666. 'batch' => array(
  667. 'description' => 'A serialized array containing the processing data for the batch.',
  668. 'type' => 'blob',
  669. 'not null' => FALSE,
  670. 'size' => 'big',
  671. ),
  672. ),
  673. 'primary key' => array('bid'),
  674. 'indexes' => array(
  675. 'token' => array('token'),
  676. ),
  677. );
  678. $schema['blocked_ips'] = array(
  679. 'description' => 'Stores blocked IP addresses.',
  680. 'fields' => array(
  681. 'iid' => array(
  682. 'description' => 'Primary Key: unique ID for IP addresses.',
  683. 'type' => 'serial',
  684. 'unsigned' => TRUE,
  685. 'not null' => TRUE,
  686. ),
  687. 'ip' => array(
  688. 'description' => 'IP address',
  689. 'type' => 'varchar',
  690. 'length' => 40,
  691. 'not null' => TRUE,
  692. 'default' => '',
  693. ),
  694. ),
  695. 'indexes' => array(
  696. 'blocked_ip' => array('ip'),
  697. ),
  698. 'primary key' => array('iid'),
  699. );
  700. $schema['cache'] = array(
  701. 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
  702. 'fields' => array(
  703. 'cid' => array(
  704. 'description' => 'Primary Key: Unique cache ID.',
  705. 'type' => 'varchar',
  706. 'length' => 255,
  707. 'not null' => TRUE,
  708. 'default' => '',
  709. ),
  710. 'data' => array(
  711. 'description' => 'A collection of data to cache.',
  712. 'type' => 'blob',
  713. 'not null' => FALSE,
  714. 'size' => 'big',
  715. ),
  716. 'expire' => array(
  717. 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
  718. 'type' => 'int',
  719. 'not null' => TRUE,
  720. 'default' => 0,
  721. ),
  722. 'created' => array(
  723. 'description' => 'A Unix timestamp indicating when the cache entry was created.',
  724. 'type' => 'int',
  725. 'not null' => TRUE,
  726. 'default' => 0,
  727. ),
  728. 'serialized' => array(
  729. 'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
  730. 'type' => 'int',
  731. 'size' => 'small',
  732. 'not null' => TRUE,
  733. 'default' => 0,
  734. ),
  735. ),
  736. 'indexes' => array(
  737. 'expire' => array('expire'),
  738. ),
  739. 'primary key' => array('cid'),
  740. );
  741. $schema['cache_bootstrap'] = $schema['cache'];
  742. $schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.';
  743. $schema['cache_form'] = $schema['cache'];
  744. $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.';
  745. $schema['cache_page'] = $schema['cache'];
  746. $schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.';
  747. $schema['cache_menu'] = $schema['cache'];
  748. $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.';
  749. $schema['cache_path'] = $schema['cache'];
  750. $schema['cache_path']['description'] = 'Cache table for path alias lookup.';
  751. $schema['date_format_type'] = array(
  752. 'description' => 'Stores configured date format types.',
  753. 'fields' => array(
  754. 'type' => array(
  755. 'description' => 'The date format type, e.g. medium.',
  756. 'type' => 'varchar',
  757. 'length' => 64,
  758. 'not null' => TRUE,
  759. ),
  760. 'title' => array(
  761. 'description' => 'The human readable name of the format type.',
  762. 'type' => 'varchar',
  763. 'length' => 255,
  764. 'not null' => TRUE,
  765. ),
  766. 'locked' => array(
  767. 'description' => 'Whether or not this is a system provided format.',
  768. 'type' => 'int',
  769. 'size' => 'tiny',
  770. 'default' => 0,
  771. 'not null' => TRUE,
  772. ),
  773. ),
  774. 'primary key' => array('type'),
  775. 'indexes' => array(
  776. 'title' => array('title'),
  777. ),
  778. );
  779. // This table's name is plural as some versions of MySQL can't create a
  780. // table named 'date_format'.
  781. $schema['date_formats'] = array(
  782. 'description' => 'Stores configured date formats.',
  783. 'fields' => array(
  784. 'dfid' => array(
  785. 'description' => 'The date format identifier.',
  786. 'type' => 'serial',
  787. 'not null' => TRUE,
  788. 'unsigned' => TRUE,
  789. ),
  790. 'format' => array(
  791. 'description' => 'The date format string.',
  792. 'type' => 'varchar',
  793. 'length' => 100,
  794. 'not null' => TRUE,
  795. 'binary' => TRUE,
  796. ),
  797. 'type' => array(
  798. 'description' => 'The date format type, e.g. medium.',
  799. 'type' => 'varchar',
  800. 'length' => 64,
  801. 'not null' => TRUE,
  802. ),
  803. 'locked' => array(
  804. 'description' => 'Whether or not this format can be modified.',
  805. 'type' => 'int',
  806. 'size' => 'tiny',
  807. 'default' => 0,
  808. 'not null' => TRUE,
  809. ),
  810. ),
  811. 'primary key' => array('dfid'),
  812. 'unique keys' => array('formats' => array('format', 'type')),
  813. );
  814. $schema['date_format_locale'] = array(
  815. 'description' => 'Stores configured date formats for each locale.',
  816. 'fields' => array(
  817. 'format' => array(
  818. 'description' => 'The date format string.',
  819. 'type' => 'varchar',
  820. 'length' => 100,
  821. 'not null' => TRUE,
  822. 'binary' => TRUE,
  823. ),
  824. 'type' => array(
  825. 'description' => 'The date format type, e.g. medium.',
  826. 'type' => 'varchar',
  827. 'length' => 64,
  828. 'not null' => TRUE,
  829. ),
  830. 'language' => array(
  831. 'description' => 'A {languages}.language for this format to be used with.',
  832. 'type' => 'varchar',
  833. 'length' => 12,
  834. 'not null' => TRUE,
  835. ),
  836. ),
  837. 'primary key' => array('type', 'language'),
  838. );
  839. $schema['file_managed'] = array(
  840. 'description' => 'Stores information for uploaded files.',
  841. 'fields' => array(
  842. 'fid' => array(
  843. 'description' => 'File ID.',
  844. 'type' => 'serial',
  845. 'unsigned' => TRUE,
  846. 'not null' => TRUE,
  847. ),
  848. 'uid' => array(
  849. 'description' => 'The {users}.uid of the user who is associated with the file.',
  850. 'type' => 'int',
  851. 'unsigned' => TRUE,
  852. 'not null' => TRUE,
  853. 'default' => 0,
  854. ),
  855. 'filename' => array(
  856. 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
  857. 'type' => 'varchar',
  858. 'length' => 255,
  859. 'not null' => TRUE,
  860. 'default' => '',
  861. ),
  862. 'uri' => array(
  863. 'description' => 'The URI to access the file (either local or remote).',
  864. 'type' => 'varchar',
  865. 'length' => 255,
  866. 'not null' => TRUE,
  867. 'default' => '',
  868. 'binary' => TRUE,
  869. ),
  870. 'filemime' => array(
  871. 'description' => "The file's MIME type.",
  872. 'type' => 'varchar',
  873. 'length' => 255,
  874. 'not null' => TRUE,
  875. 'default' => '',
  876. ),
  877. 'filesize' => array(
  878. 'description' => 'The size of the file in bytes.',
  879. 'type' => 'int',
  880. 'size' => 'big',
  881. 'unsigned' => TRUE,
  882. 'not null' => TRUE,
  883. 'default' => 0,
  884. ),
  885. 'status' => array(
  886. 'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
  887. 'type' => 'int',
  888. 'not null' => TRUE,
  889. 'default' => 0,
  890. 'size' => 'tiny',
  891. ),
  892. 'timestamp' => array(
  893. 'description' => 'UNIX timestamp for when the file was added.',
  894. 'type' => 'int',
  895. 'unsigned' => TRUE,
  896. 'not null' => TRUE,
  897. 'default' => 0,
  898. ),
  899. ),
  900. 'indexes' => array(
  901. 'uid' => array('uid'),
  902. 'status' => array('status'),
  903. 'timestamp' => array('timestamp'),
  904. ),
  905. 'unique keys' => array(
  906. 'uri' => array('uri'),
  907. ),
  908. 'primary key' => array('fid'),
  909. 'foreign keys' => array(
  910. 'file_owner' => array(
  911. 'table' => 'users',
  912. 'columns' => array('uid' => 'uid'),
  913. ),
  914. ),
  915. );
  916. $schema['file_usage'] = array(
  917. 'description' => 'Track where a file is used.',
  918. 'fields' => array(
  919. 'fid' => array(
  920. 'description' => 'File ID.',
  921. 'type' => 'int',
  922. 'unsigned' => TRUE,
  923. 'not null' => TRUE,
  924. ),
  925. 'module' => array(
  926. 'description' => 'The name of the module that is using the file.',
  927. 'type' => 'varchar',
  928. 'length' => 255,
  929. 'not null' => TRUE,
  930. 'default' => '',
  931. ),
  932. 'type' => array(
  933. 'description' => 'The name of the object type in which the file is used.',
  934. 'type' => 'varchar',
  935. 'length' => 64,
  936. 'not null' => TRUE,
  937. 'default' => '',
  938. ),
  939. 'id' => array(
  940. 'description' => 'The primary key of the object using the file.',
  941. 'type' => 'int',
  942. 'unsigned' => TRUE,
  943. 'not null' => TRUE,
  944. 'default' => 0,
  945. ),
  946. 'count' => array(
  947. 'description' => 'The number of times this file is used by this object.',
  948. 'type' => 'int',
  949. 'unsigned' => TRUE,
  950. 'not null' => TRUE,
  951. 'default' => 0,
  952. ),
  953. ),
  954. 'primary key' => array('fid', 'type', 'id', 'module'),
  955. 'indexes' => array(
  956. 'type_id' => array('type', 'id'),
  957. 'fid_count' => array('fid', 'count'),
  958. 'fid_module' => array('fid', 'module'),
  959. ),
  960. );
  961. $schema['flood'] = array(
  962. 'description' => 'Flood controls the threshold of events, such as the number of contact attempts.',
  963. 'fields' => array(
  964. 'fid' => array(
  965. 'description' => 'Unique flood event ID.',
  966. 'type' => 'serial',
  967. 'not null' => TRUE,
  968. ),
  969. 'event' => array(
  970. 'description' => 'Name of event (e.g. contact).',
  971. 'type' => 'varchar',
  972. 'length' => 64,
  973. 'not null' => TRUE,
  974. 'default' => '',
  975. ),
  976. 'identifier' => array(
  977. 'description' => 'Identifier of the visitor, such as an IP address or hostname.',
  978. 'type' => 'varchar',
  979. 'length' => 128,
  980. 'not null' => TRUE,
  981. 'default' => '',
  982. ),
  983. 'timestamp' => array(
  984. 'description' => 'Timestamp of the event.',
  985. 'type' => 'int',
  986. 'not null' => TRUE,
  987. 'default' => 0,
  988. ),
  989. 'expiration' => array(
  990. 'description' => 'Expiration timestamp. Expired events are purged on cron run.',
  991. 'type' => 'int',
  992. 'not null' => TRUE,
  993. 'default' => 0,
  994. ),
  995. ),
  996. 'primary key' => array('fid'),
  997. 'indexes' => array(
  998. 'allow' => array('event', 'identifier', 'timestamp'),
  999. 'purge' => array('expiration'),
  1000. ),
  1001. );
  1002. $schema['menu_router'] = array(
  1003. 'description' => 'Maps paths to various callbacks (access, page and title)',
  1004. 'fields' => array(
  1005. 'path' => array(
  1006. 'description' => 'Primary Key: the Drupal path this entry describes',
  1007. 'type' => 'varchar',
  1008. 'length' => 255,
  1009. 'not null' => TRUE,
  1010. 'default' => '',
  1011. ),
  1012. 'load_functions' => array(
  1013. '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.',
  1014. 'type' => 'blob',
  1015. 'not null' => TRUE,
  1016. ),
  1017. 'to_arg_functions' => array(
  1018. '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.',
  1019. 'type' => 'blob',
  1020. 'not null' => TRUE,
  1021. ),
  1022. 'access_callback' => array(
  1023. 'description' => 'The callback which determines the access to this router path. Defaults to user_access.',
  1024. 'type' => 'varchar',
  1025. 'length' => 255,
  1026. 'not null' => TRUE,
  1027. 'default' => '',
  1028. ),
  1029. 'access_arguments' => array(
  1030. 'description' => 'A serialized array of arguments for the access callback.',
  1031. 'type' => 'blob',
  1032. 'not null' => FALSE,
  1033. ),
  1034. 'page_callback' => array(
  1035. 'description' => 'The name of the function that renders the page.',
  1036. 'type' => 'varchar',
  1037. 'length' => 255,
  1038. 'not null' => TRUE,
  1039. 'default' => '',
  1040. ),
  1041. 'page_arguments' => array(
  1042. 'description' => 'A serialized array of arguments for the page callback.',
  1043. 'type' => 'blob',
  1044. 'not null' => FALSE,
  1045. ),
  1046. 'delivery_callback' => array(
  1047. 'description' => 'The name of the function that sends the result of the page_callback function to the browser.',
  1048. 'type' => 'varchar',
  1049. 'length' => 255,
  1050. 'not null' => TRUE,
  1051. 'default' => '',
  1052. ),
  1053. 'fit' => array(
  1054. 'description' => 'A numeric representation of how specific the path is.',
  1055. 'type' => 'int',
  1056. 'not null' => TRUE,
  1057. 'default' => 0,
  1058. ),
  1059. 'number_parts' => array(
  1060. 'description' => 'Number of parts in this router path.',
  1061. 'type' => 'int',
  1062. 'not null' => TRUE,
  1063. 'default' => 0,
  1064. 'size' => 'small',
  1065. ),
  1066. 'context' => array(
  1067. 'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.',
  1068. 'type' => 'int',
  1069. 'not null' => TRUE,
  1070. 'default' => 0,
  1071. ),
  1072. 'tab_parent' => array(
  1073. 'description' => 'Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).',
  1074. 'type' => 'varchar',
  1075. 'length' => 255,
  1076. 'not null' => TRUE,
  1077. 'default' => '',
  1078. ),
  1079. 'tab_root' => array(
  1080. '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.',
  1081. 'type' => 'varchar',
  1082. 'length' => 255,
  1083. 'not null' => TRUE,
  1084. 'default' => '',
  1085. ),
  1086. 'title' => array(
  1087. 'description' => 'The title for the current page, or the title for the tab if this is a local task.',
  1088. 'type' => 'varchar',
  1089. 'length' => 255,
  1090. 'not null' => TRUE,
  1091. 'default' => '',
  1092. ),
  1093. 'title_callback' => array(
  1094. 'description' => 'A function which will alter the title. Defaults to t()',
  1095. 'type' => 'varchar',
  1096. 'length' => 255,
  1097. 'not null' => TRUE,
  1098. 'default' => '',
  1099. ),
  1100. 'title_arguments' => array(
  1101. '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.',
  1102. 'type' => 'varchar',
  1103. 'length' => 255,
  1104. 'not null' => TRUE,
  1105. 'default' => '',
  1106. ),
  1107. 'theme_callback' => array(
  1108. '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.',
  1109. 'type' => 'varchar',
  1110. 'length' => 255,
  1111. 'not null' => TRUE,
  1112. 'default' => '',
  1113. ),
  1114. 'theme_arguments' => array(
  1115. 'description' => 'A serialized array of arguments for the theme callback.',
  1116. 'type' => 'varchar',
  1117. 'length' => 255,
  1118. 'not null' => TRUE,
  1119. 'default' => '',
  1120. ),
  1121. 'type' => array(
  1122. 'description' => 'Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.',
  1123. 'type' => 'int',
  1124. 'not null' => TRUE,
  1125. 'default' => 0,
  1126. ),
  1127. 'description' => array(
  1128. 'description' => 'A description of this item.',
  1129. 'type' => 'text',
  1130. 'not null' => TRUE,
  1131. ),
  1132. 'position' => array(
  1133. 'description' => 'The position of the block (left or right) on the system administration page for this item.',
  1134. 'type' => 'varchar',
  1135. 'length' => 255,
  1136. 'not null' => TRUE,
  1137. 'default' => '',
  1138. ),
  1139. 'weight' => array(
  1140. 'description' => 'Weight of the element. Lighter weights are higher up, heavier weights go down.',
  1141. 'type' => 'int',
  1142. 'not null' => TRUE,
  1143. 'default' => 0,
  1144. ),
  1145. 'include_file' => array(
  1146. 'description' => 'The file to include for this element, usually the page callback function lives in this file.',
  1147. 'type' => 'text',
  1148. 'size' => 'medium',
  1149. ),
  1150. ),
  1151. 'indexes' => array(
  1152. 'fit' => array('fit'),
  1153. 'tab_parent' => array(array('tab_parent', 64), 'weight', 'title'),
  1154. 'tab_root_weight_title' => array(array('tab_root', 64), 'weight', 'title'),
  1155. ),
  1156. 'primary key' => array('path'),
  1157. );
  1158. $schema['menu_links'] = array(
  1159. 'description' => 'Contains the individual links within a menu.',
  1160. 'fields' => array(
  1161. 'menu_name' => array(
  1162. 'description' => "The menu name. All links with the same menu name (such as 'navigation') are part of the same menu.",
  1163. 'type' => 'varchar',
  1164. 'length' => 32,
  1165. 'not null' => TRUE,
  1166. 'default' => '',
  1167. ),
  1168. 'mlid' => array(
  1169. 'description' => 'The menu link ID (mlid) is the integer primary key.',
  1170. 'type' => 'serial',
  1171. 'unsigned' => TRUE,
  1172. 'not null' => TRUE,
  1173. ),
  1174. 'plid' => array(
  1175. 'description' => 'The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.',
  1176. 'type' => 'int',
  1177. 'unsigned' => TRUE,
  1178. 'not null' => TRUE,
  1179. 'default' => 0,
  1180. ),
  1181. 'link_path' => array(
  1182. 'description' => 'The Drupal path or external path this link points to.',
  1183. 'type' => 'varchar',
  1184. 'length' => 255,
  1185. 'not null' => TRUE,
  1186. 'default' => '',
  1187. ),
  1188. 'router_path' => array(
  1189. 'description' => 'For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.',
  1190. 'type' => 'varchar',
  1191. 'length' => 255,
  1192. 'not null' => TRUE,
  1193. 'default' => '',
  1194. ),
  1195. 'link_title' => array(
  1196. 'description' => 'The text displayed for the link, which may be modified by a title callback stored in {menu_router}.',
  1197. 'type' => 'varchar',
  1198. 'length' => 255,
  1199. 'not null' => TRUE,
  1200. 'default' => '',
  1201. 'translatable' => TRUE,
  1202. ),
  1203. 'options' => array(
  1204. 'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',
  1205. 'type' => 'blob',
  1206. 'not null' => FALSE,
  1207. 'translatable' => TRUE,
  1208. ),
  1209. 'module' => array(
  1210. 'description' => 'The name of the module that generated this link.',
  1211. 'type' => 'varchar',
  1212. 'length' => 255,
  1213. 'not null' => TRUE,
  1214. 'default' => 'system',
  1215. ),
  1216. 'hidden' => array(
  1217. 'description' => 'A flag for whether the link should be rendered in menus. (1 = a disabled menu item that may be shown on admin screens, -1 = a menu callback, 0 = a normal, visible link)',
  1218. 'type' => 'int',
  1219. 'not null' => TRUE,
  1220. 'default' => 0,
  1221. 'size' => 'small',
  1222. ),
  1223. 'external' => array(
  1224. 'description' => 'A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).',
  1225. 'type' => 'int',
  1226. 'not null' => TRUE,
  1227. 'default' => 0,
  1228. 'size' => 'small',
  1229. ),
  1230. 'has_children' => array(
  1231. 'description' => 'Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).',
  1232. 'type' => 'int',
  1233. 'not null' => TRUE,
  1234. 'default' => 0,
  1235. 'size' => 'small',
  1236. ),
  1237. 'expanded' => array(
  1238. 'description' => 'Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded)',
  1239. 'type' => 'int',
  1240. 'not null' => TRUE,
  1241. 'default' => 0,
  1242. 'size' => 'small',
  1243. ),
  1244. 'weight' => array(
  1245. 'description' => 'Link weight among links in the same menu at the same depth.',
  1246. 'type' => 'int',
  1247. 'not null' => TRUE,
  1248. 'default' => 0,
  1249. ),
  1250. 'depth' => array(
  1251. 'description' => 'The depth relative to the top level. A link with plid == 0 will have depth == 1.',
  1252. 'type' => 'int',
  1253. 'not null' => TRUE,
  1254. 'default' => 0,
  1255. 'size' => 'small',
  1256. ),
  1257. 'customized' => array(
  1258. 'description' => 'A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).',
  1259. 'type' => 'int',
  1260. 'not null' => TRUE,
  1261. 'default' => 0,
  1262. 'size' => 'small',
  1263. ),
  1264. 'p1' => array(
  1265. 'description' => 'The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the plid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.',
  1266. 'type' => 'int',
  1267. 'unsigned' => TRUE,
  1268. 'not null' => TRUE,
  1269. 'default' => 0,
  1270. ),
  1271. 'p2' => array(
  1272. 'description' => 'The second mlid in the materialized path. See p1.',
  1273. 'type' => 'int',
  1274. 'unsigned' => TRUE,
  1275. 'not null' => TRUE,
  1276. 'default' => 0,
  1277. ),
  1278. 'p3' => array(
  1279. 'description' => 'The third mlid in the materialized path. See p1.',
  1280. 'type' => 'int',
  1281. 'unsigned' => TRUE,
  1282. 'not null' => TRUE,
  1283. 'default' => 0,
  1284. ),
  1285. 'p4' => array(
  1286. 'description' => 'The fourth mlid in the materialized path. See p1.',
  1287. 'type' => 'int',
  1288. 'unsigned' => TRUE,
  1289. 'not null' => TRUE,
  1290. 'default' => 0,
  1291. ),
  1292. 'p5' => array(
  1293. 'description' => 'The fifth mlid in the materialized path. See p1.',
  1294. 'type' => 'int',
  1295. 'unsigned' => TRUE,
  1296. 'not null' => TRUE,
  1297. 'default' => 0,
  1298. ),
  1299. 'p6' => array(
  1300. 'description' => 'The sixth mlid in the materialized path. See p1.',
  1301. 'type' => 'int',
  1302. 'unsigned' => TRUE,
  1303. 'not null' => TRUE,
  1304. 'default' => 0,
  1305. ),
  1306. 'p7' => array(
  1307. 'description' => 'The seventh mlid in the materialized path. See p1.',
  1308. 'type' => 'int',
  1309. 'unsigned' => TRUE,
  1310. 'not null' => TRUE,
  1311. 'default' => 0,
  1312. ),
  1313. 'p8' => array(
  1314. 'description' => 'The eighth mlid in the materialized path. See p1.',
  1315. 'type' => 'int',
  1316. 'unsigned' => TRUE,
  1317. 'not null' => TRUE,
  1318. 'default' => 0,
  1319. ),
  1320. 'p9' => array(
  1321. 'description' => 'The ninth mlid in the materialized path. See p1.',
  1322. 'type' => 'int',
  1323. 'unsigned' => TRUE,
  1324. 'not null' => TRUE,
  1325. 'default' => 0,
  1326. ),
  1327. 'updated' => array(
  1328. 'description' => 'Flag that indicates that this link was generated during the update from Drupal 5.',
  1329. 'type' => 'int',
  1330. 'not null' => TRUE,
  1331. 'default' => 0,
  1332. 'size' => 'small',
  1333. ),
  1334. ),
  1335. 'indexes' => array(
  1336. 'path_menu' => array(array('link_path', 128), 'menu_name'),
  1337. 'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'),
  1338. 'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'),
  1339. 'router_path' => array(array('router_path', 128)),
  1340. ),
  1341. 'primary key' => array('mlid'),
  1342. );
  1343. $schema['queue'] = array(
  1344. 'description' => 'Stores items in queues.',
  1345. 'fields' => array(
  1346. 'item_id' => array(
  1347. 'type' => 'serial',
  1348. 'unsigned' => TRUE,
  1349. 'not null' => TRUE,
  1350. 'description' => 'Primary Key: Unique item ID.',
  1351. ),
  1352. 'name' => array(
  1353. 'type' => 'varchar',
  1354. 'length' => 255,
  1355. 'not null' => TRUE,
  1356. 'default' => '',
  1357. 'description' => 'The queue name.',
  1358. ),
  1359. 'data' => array(
  1360. 'type' => 'blob',
  1361. 'not null' => FALSE,
  1362. 'size' => 'big',
  1363. 'serialize' => TRUE,
  1364. 'description' => 'The arbitrary data for the item.',
  1365. ),
  1366. 'expire' => array(
  1367. 'type' => 'int',
  1368. 'not null' => TRUE,
  1369. 'default' => 0,
  1370. 'description' => 'Timestamp when the claim lease expires on the item.',
  1371. ),
  1372. 'created' => array(
  1373. 'type' => 'int',
  1374. 'not null' => TRUE,
  1375. 'default' => 0,
  1376. 'description' => 'Timestamp when the item was created.',
  1377. ),
  1378. ),
  1379. 'primary key' => array('item_id'),
  1380. 'indexes' => array(
  1381. 'name_created' => array('name', 'created'),
  1382. 'expire' => array('expire'),
  1383. ),
  1384. );
  1385. $schema['registry'] = array(
  1386. 'description' => "Each record is a function, class, or interface name and the file it is in.",
  1387. 'fields' => array(
  1388. 'name' => array(
  1389. 'description' => 'The name of the function, class, or interface.',
  1390. 'type' => 'varchar',
  1391. 'length' => 255,
  1392. 'not null' => TRUE,
  1393. 'default' => '',
  1394. ),
  1395. 'type' => array(
  1396. 'description' => 'Either function or class or interface.',
  1397. 'type' => 'varchar',
  1398. 'length' => 9,
  1399. 'not null' => TRUE,
  1400. 'default' => '',
  1401. ),
  1402. 'filename' => array(
  1403. 'description' => 'Name of the file.',
  1404. 'type' => 'varchar',
  1405. 'length' => 255,
  1406. 'not null' => TRUE,
  1407. ),
  1408. 'module' => array(
  1409. 'description' => 'Name of the module the file belongs to.',
  1410. 'type' => 'varchar',
  1411. 'length' => 255,
  1412. 'not null' => TRUE,
  1413. 'default' => ''
  1414. ),
  1415. 'weight' => array(
  1416. 'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
  1417. 'type' => 'int',
  1418. 'not null' => TRUE,
  1419. 'default' => 0,
  1420. ),
  1421. ),
  1422. 'primary key' => array('name', 'type'),
  1423. 'indexes' => array(
  1424. 'hook' => array('type', 'weight', 'module'),
  1425. ),
  1426. );
  1427. $schema['registry_file'] = array(
  1428. 'description' => "Files parsed to build the registry.",
  1429. 'fields' => array(
  1430. 'filename' => array(
  1431. 'description' => 'Path to the file.',
  1432. 'type' => 'varchar',
  1433. 'length' => 255,
  1434. 'not null' => TRUE,
  1435. ),
  1436. 'hash' => array(
  1437. 'description' => "sha-256 hash of the file's contents when last parsed.",
  1438. 'type' => 'varchar',
  1439. 'length' => 64,
  1440. 'not null' => TRUE,
  1441. ),
  1442. ),
  1443. 'primary key' => array('filename'),
  1444. );
  1445. $schema['semaphore'] = array(
  1446. 'description' => 'Table for holding semaphores, locks, flags, etc. that cannot be stored as Drupal variables since they must not be cached.',
  1447. 'fields' => array(
  1448. 'name' => array(
  1449. 'description' => 'Primary Key: Unique name.',
  1450. 'type' => 'varchar',
  1451. 'length' => 255,
  1452. 'not null' => TRUE,
  1453. 'default' => ''
  1454. ),
  1455. 'value' => array(
  1456. 'description' => 'A value for the semaphore.',
  1457. 'type' => 'varchar',
  1458. 'length' => 255,
  1459. 'not null' => TRUE,
  1460. 'default' => ''
  1461. ),
  1462. 'expire' => array(
  1463. 'description' => 'A Unix timestamp with microseconds indicating when the semaphore should expire.',
  1464. 'type' => 'float',
  1465. 'size' => 'big',
  1466. 'not null' => TRUE
  1467. ),
  1468. ),
  1469. 'indexes' => array(
  1470. 'value' => array('value'),
  1471. 'expire' => array('expire'),
  1472. ),
  1473. 'primary key' => array('name'),
  1474. );
  1475. $schema['sequences'] = array(
  1476. 'description' => 'Stores IDs.',
  1477. 'fields' => array(
  1478. 'value' => array(
  1479. 'description' => 'The value of the sequence.',
  1480. 'type' => 'serial',
  1481. 'unsigned' => TRUE,
  1482. 'not null' => TRUE,
  1483. ),
  1484. ),
  1485. 'primary key' => array('value'),
  1486. );
  1487. $schema['sessions'] = array(
  1488. 'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
  1489. 'fields' => array(
  1490. 'uid' => array(
  1491. 'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
  1492. 'type' => 'int',
  1493. 'unsigned' => TRUE,
  1494. 'not null' => TRUE,
  1495. ),
  1496. 'sid' => array(
  1497. 'description' => "A session ID. The value is generated by Drupal's session handlers.",
  1498. 'type' => 'varchar',
  1499. 'length' => 128,
  1500. 'not null' => TRUE,
  1501. ),
  1502. 'ssid' => array(
  1503. 'description' => "Secure session ID. The value is generated by Drupal's session handlers.",
  1504. 'type' => 'varchar',
  1505. 'length' => 128,
  1506. 'not null' => TRUE,
  1507. 'default' => '',
  1508. ),
  1509. 'hostname' => array(
  1510. 'description' => 'The IP address that last used this session ID (sid).',
  1511. 'type' => 'varchar',
  1512. 'length' => 128,
  1513. 'not null' => TRUE,
  1514. 'default' => '',
  1515. ),
  1516. 'timestamp' => array(
  1517. 'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
  1518. 'type' => 'int',
  1519. 'not null' => TRUE,
  1520. 'default' => 0,
  1521. ),
  1522. 'cache' => array(
  1523. 'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
  1524. 'type' => 'int',
  1525. 'not null' => TRUE,
  1526. 'default' => 0,
  1527. ),
  1528. 'session' => array(
  1529. '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.',
  1530. 'type' => 'blob',
  1531. 'not null' => FALSE,
  1532. 'size' => 'big',
  1533. ),
  1534. ),
  1535. 'primary key' => array(
  1536. 'sid',
  1537. 'ssid',
  1538. ),
  1539. 'indexes' => array(
  1540. 'timestamp' => array('timestamp'),
  1541. 'uid' => array('uid'),
  1542. 'ssid' => array('ssid'),
  1543. ),
  1544. 'foreign keys' => array(
  1545. 'session_user' => array(
  1546. 'table' => 'users',
  1547. 'columns' => array('uid' => 'uid'),
  1548. ),
  1549. ),
  1550. );
  1551. $schema['system'] = array(
  1552. 'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.",
  1553. 'fields' => array(
  1554. 'filename' => array(
  1555. 'description' => 'The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.',
  1556. 'type' => 'varchar',
  1557. 'length' => 255,
  1558. 'not null' => TRUE,
  1559. 'default' => '',
  1560. ),
  1561. 'name' => array(
  1562. 'description' => 'The name of the item; e.g. node.',
  1563. 'type' => 'varchar',
  1564. 'length' => 255,
  1565. 'not null' => TRUE,
  1566. 'default' => '',
  1567. ),
  1568. 'type' => array(
  1569. 'description' => 'The type of the item, either module, theme, or theme_engine.',
  1570. 'type' => 'varchar',
  1571. 'length' => 12,
  1572. 'not null' => TRUE,
  1573. 'default' => '',
  1574. ),
  1575. 'owner' => array(
  1576. 'description' => "A theme's 'parent' . Can be either a theme or an engine.",
  1577. 'type' => 'varchar',
  1578. 'length' => 255,
  1579. 'not null' => TRUE,
  1580. 'default' => '',
  1581. ),
  1582. 'status' => array(
  1583. 'description' => 'Boolean indicating whether or not this item is enabled.',
  1584. 'type' => 'int',
  1585. 'not null' => TRUE,
  1586. 'default' => 0,
  1587. ),
  1588. 'bootstrap' => array(
  1589. 'description' => "Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted).",
  1590. 'type' => 'int',
  1591. 'not null' => TRUE,
  1592. 'default' => 0,
  1593. ),
  1594. 'schema_version' => array(
  1595. 'description' => "The module's database schema version number. -1 if the module is not installed (its tables do not exist); 0 or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed.",
  1596. 'type' => 'int',
  1597. 'not null' => TRUE,
  1598. 'default' => -1,
  1599. 'size' => 'small',
  1600. ),
  1601. 'weight' => array(
  1602. 'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
  1603. 'type' => 'int',
  1604. 'not null' => TRUE,
  1605. 'default' => 0,
  1606. ),
  1607. 'info' => array(
  1608. 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
  1609. 'type' => 'blob',
  1610. 'not null' => FALSE,
  1611. ),
  1612. ),
  1613. 'primary key' => array('filename'),
  1614. 'indexes' => array(
  1615. 'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'),
  1616. 'type_name' => array('type', 'name'),
  1617. ),
  1618. );
  1619. $schema['url_alias'] = array(
  1620. 'description' => 'A list of URL aliases for Drupal paths; a user may visit either the source or destination path.',
  1621. 'fields' => array(
  1622. 'pid' => array(
  1623. 'description' => 'A unique path alias identifier.',
  1624. 'type' => 'serial',
  1625. 'unsigned' => TRUE,
  1626. 'not null' => TRUE,
  1627. ),
  1628. 'source' => array(
  1629. 'description' => 'The Drupal path this alias is for; e.g. node/12.',
  1630. 'type' => 'varchar',
  1631. 'length' => 255,
  1632. 'not null' => TRUE,
  1633. 'default' => '',
  1634. ),
  1635. 'alias' => array(
  1636. 'description' => 'The alias for this path; e.g. title-of-the-story.',
  1637. 'type' => 'varchar',
  1638. 'length' => 255,
  1639. 'not null' => TRUE,
  1640. 'default' => '',
  1641. ),
  1642. 'language' => array(
  1643. 'description' => "The language 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.",
  1644. 'type' => 'varchar',
  1645. 'length' => 12,
  1646. 'not null' => TRUE,
  1647. 'default' => '',
  1648. ),
  1649. ),
  1650. 'primary key' => array('pid'),
  1651. 'indexes' => array(
  1652. 'alias_language_pid' => array('alias', 'language', 'pid'),
  1653. 'source_language_pid' => array('source', 'language', 'pid'),
  1654. ),
  1655. );
  1656. return $schema;
  1657. }
  1658. /**
  1659. * The cache schema corresponding to system_update_7054.
  1660. *
  1661. * Drupal 7 adds several new cache tables. Since they all have identical schema
  1662. * this helper function allows them to re-use the same definition, without
  1663. * relying on system_schema(), which may change with future updates.
  1664. */
  1665. function system_schema_cache_7054() {
  1666. return array(
  1667. 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
  1668. 'fields' => array(
  1669. 'cid' => array(
  1670. 'description' => 'Primary Key: Unique cache ID.',
  1671. 'type' => 'varchar',
  1672. 'length' => 255,
  1673. 'not null' => TRUE,
  1674. 'default' => '',
  1675. ),
  1676. 'data' => array(
  1677. 'description' => 'A collection of data to cache.',
  1678. 'type' => 'blob',
  1679. 'not null' => FALSE,
  1680. 'size' => 'big',
  1681. ),
  1682. 'expire' => array(
  1683. 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
  1684. 'type' => 'int',
  1685. 'not null' => TRUE,
  1686. 'default' => 0,
  1687. ),
  1688. 'created' => array(
  1689. 'description' => 'A Unix timestamp indicating when the cache entry was created.',
  1690. 'type' => 'int',
  1691. 'not null' => TRUE,
  1692. 'default' => 0,
  1693. ),
  1694. 'serialized' => array(
  1695. 'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
  1696. 'type' => 'int',
  1697. 'size' => 'small',
  1698. 'not null' => TRUE,
  1699. 'default' => 0,
  1700. ),
  1701. ),
  1702. 'indexes' => array(
  1703. 'expire' => array('expire'),
  1704. ),
  1705. 'primary key' => array('cid'),
  1706. );
  1707. }
  1708. // Updates for core.
  1709. function system_update_last_removed() {
  1710. return 6055;
  1711. }
  1712. /**
  1713. * Implements hook_update_dependencies().
  1714. */
  1715. function system_update_dependencies() {
  1716. // system_update_7053() queries the {block} table, so it must run after
  1717. // block_update_7002(), which creates that table.
  1718. $dependencies['system'][7053] = array(
  1719. 'block' => 7002,
  1720. );
  1721. // system_update_7061() queries the {node_revision} table, so it must run
  1722. // after node_update_7001(), which renames the {node_revisions} table.
  1723. $dependencies['system'][7061] = array(
  1724. 'node' => 7001,
  1725. );
  1726. // system_update_7067() migrates role permissions and therefore must run
  1727. // after the {role} and {role_permission} tables are properly set up, which
  1728. // happens in user_update_7007().
  1729. $dependencies['system'][7067] = array(
  1730. 'user' => 7007,
  1731. );
  1732. return $dependencies;
  1733. }
  1734. /**
  1735. * @defgroup updates-6.x-to-7.x Updates from 6.x to 7.x
  1736. * @{
  1737. * Update functions from 6.x to 7.x.
  1738. */
  1739. /**
  1740. * Rename blog and forum permissions to be consistent with other content types.
  1741. */
  1742. function system_update_7000() {
  1743. $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
  1744. foreach ($result as $role) {
  1745. $renamed_permission = $role->perm;
  1746. $renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $renamed_permission);
  1747. $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ blog\ entries(?=,|$)/', 'edit own blog content', $renamed_permission);
  1748. $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ blog\ entry(?=,|$)/', 'edit any blog content', $renamed_permission);
  1749. $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ blog\ entries(?=,|$)/', 'delete own blog content', $renamed_permission);
  1750. $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ blog\ entry(?=,|$)/', 'delete any blog content', $renamed_permission);
  1751. $renamed_permission = preg_replace('/(?<=^|,\ )create\ forum\ topics(?=,|$)/', 'create forum content', $renamed_permission);
  1752. $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ forum\ topic(?=,|$)/', 'delete any forum content', $renamed_permission);
  1753. $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ forum\ topics(?=,|$)/', 'delete own forum content', $renamed_permission);
  1754. $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ forum\ topic(?=,|$)/', 'edit any forum content', $renamed_permission);
  1755. $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ forum\ topics(?=,|$)/', 'edit own forum content', $renamed_permission);
  1756. if ($renamed_permission != $role->perm) {
  1757. db_update('permission')
  1758. ->fields(array('perm' => $renamed_permission))
  1759. ->condition('rid', $role->rid)
  1760. ->execute();
  1761. }
  1762. }
  1763. }
  1764. /**
  1765. * Generate a cron key and save it in the variables table.
  1766. */
  1767. function system_update_7001() {
  1768. variable_set('cron_key', drupal_random_key());
  1769. }
  1770. /**
  1771. * Add a table to store blocked IP addresses.
  1772. */
  1773. function system_update_7002() {
  1774. $schema['blocked_ips'] = array(
  1775. 'description' => 'Stores blocked IP addresses.',
  1776. 'fields' => array(
  1777. 'iid' => array(
  1778. 'description' => 'Primary Key: unique ID for IP addresses.',
  1779. 'type' => 'serial',
  1780. 'unsigned' => TRUE,
  1781. 'not null' => TRUE,
  1782. ),
  1783. 'ip' => array(
  1784. 'description' => 'IP address',
  1785. 'type' => 'varchar',
  1786. 'length' => 32,
  1787. 'not null' => TRUE,
  1788. 'default' => '',
  1789. ),
  1790. ),
  1791. 'indexes' => array(
  1792. 'blocked_ip' => array('ip'),
  1793. ),
  1794. 'primary key' => array('iid'),
  1795. );
  1796. db_create_table('blocked_ips', $schema['blocked_ips']);
  1797. }
  1798. /**
  1799. * Update {blocked_ips} with valid IP addresses from {access}.
  1800. */
  1801. function system_update_7003() {
  1802. $messages = array();
  1803. $type = 'host';
  1804. $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
  1805. ':status' => 0,
  1806. ':type' => $type,
  1807. ));
  1808. foreach ($result as $blocked) {
  1809. if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {
  1810. db_insert('blocked_ips')
  1811. ->fields(array('ip' => $blocked->mask))
  1812. ->execute();
  1813. }
  1814. else {
  1815. $invalid_host = check_plain($blocked->mask);
  1816. $messages[] = t('The host !host is no longer blocked because it is not a valid IP address.', array('!host' => $invalid_host ));
  1817. }
  1818. }
  1819. if (isset($invalid_host)) {
  1820. drupal_set_message('Drupal no longer supports wildcard IP address blocking. Visitors whose IP addresses match ranges you have previously set using <em>access rules</em> will no longer be blocked from your site when you put the site online. See the <a href="http://drupal.org/node/24302">IP address and referrer blocking Handbook page</a> for alternative methods.', 'warning');
  1821. }
  1822. // Make sure not to block any IP addresses that were specifically allowed by access rules.
  1823. if (!empty($result)) {
  1824. $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
  1825. ':status' => 1,
  1826. ':type' => $type,
  1827. ));
  1828. $or = db_condition('or');
  1829. foreach ($result as $allowed) {
  1830. $or->condition('ip', $allowed->mask, 'LIKE');
  1831. }
  1832. if (count($or)) {
  1833. db_delete('blocked_ips')
  1834. ->condition($or)
  1835. ->execute();
  1836. }
  1837. }
  1838. }
  1839. /**
  1840. * Remove hardcoded numeric deltas from all blocks in core.
  1841. */
  1842. function system_update_7004(&$sandbox) {
  1843. // Get an array of the renamed block deltas, organized by module.
  1844. $renamed_deltas = array(
  1845. 'blog' => array('0' => 'recent'),
  1846. 'book' => array('0' => 'navigation'),
  1847. 'comment' => array('0' => 'recent'),
  1848. 'forum' => array(
  1849. '0' => 'active',
  1850. '1' => 'new',
  1851. ),
  1852. 'locale' => array('0' => LANGUAGE_TYPE_INTERFACE),
  1853. 'node' => array('0' => 'syndicate'),
  1854. 'poll' => array('0' => 'recent'),
  1855. 'profile' => array('0' => 'author-information'),
  1856. 'search' => array('0' => 'form'),
  1857. 'statistics' => array('0' => 'popular'),
  1858. 'system' => array('0' => 'powered-by'),
  1859. 'user' => array(
  1860. '0' => 'login',
  1861. '1' => 'navigation',
  1862. '2' => 'new',
  1863. '3' => 'online',
  1864. ),
  1865. );
  1866. $moved_deltas = array(
  1867. 'user' => array('navigation' => 'system'),
  1868. );
  1869. // Only run this the first time through the batch update.
  1870. if (!isset($sandbox['progress'])) {
  1871. // Rename forum module's block variables.
  1872. $forum_block_num_0 = variable_get('forum_block_num_0');
  1873. if (isset($forum_block_num_0)) {
  1874. variable_set('forum_block_num_active', $forum_block_num_0);
  1875. variable_del('forum_block_num_0');
  1876. }
  1877. $forum_block_num_1 = variable_get('forum_block_num_1');
  1878. if (isset($forum_block_num_1)) {
  1879. variable_set('forum_block_num_new', $forum_block_num_1);
  1880. variable_del('forum_block_num_1');
  1881. }
  1882. }
  1883. update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas);
  1884. }
  1885. /**
  1886. * Remove throttle columns and variables.
  1887. */
  1888. function system_update_7005() {
  1889. db_drop_field('blocks', 'throttle');
  1890. db_drop_field('system', 'throttle');
  1891. variable_del('throttle_user');
  1892. variable_del('throttle_anonymous');
  1893. variable_del('throttle_level');
  1894. variable_del('throttle_probability_limiter');
  1895. }
  1896. /**
  1897. * Convert to new method of storing permissions.
  1898. */
  1899. function system_update_7007() {
  1900. // Copy the permissions from the old {permission} table to the new {role_permission} table.
  1901. $messages = array();
  1902. $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
  1903. $query = db_insert('role_permission')->fields(array('rid', 'permission'));
  1904. foreach ($result as $role) {
  1905. foreach (array_unique(explode(', ', $role->perm)) as $perm) {
  1906. $query->values(array(
  1907. 'rid' => $role->rid,
  1908. 'permission' => $perm,
  1909. ));
  1910. }
  1911. $messages[] = t('Inserted into {role_permission} the permissions for role ID !id', array('!id' => $role->rid));
  1912. }
  1913. $query->execute();
  1914. db_drop_table('permission');
  1915. return implode(', ', $messages);
  1916. }
  1917. /**
  1918. * Rename the variable for primary links.
  1919. */
  1920. function system_update_7009() {
  1921. $current_primary = variable_get('menu_primary_links_source');
  1922. if (isset($current_primary)) {
  1923. variable_set('menu_main_links_source', $current_primary);
  1924. variable_del('menu_primary_links_source');
  1925. }
  1926. }
  1927. /**
  1928. * Split the 'bypass node access' permission from 'administer nodes'.
  1929. */
  1930. function system_update_7011() {
  1931. // Get existing roles that can 'administer nodes'.
  1932. $rids = array();
  1933. $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol();
  1934. // None found.
  1935. if (empty($rids)) {
  1936. return;
  1937. }
  1938. $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
  1939. foreach ($rids as $rid) {
  1940. $insert->values(array(
  1941. 'rid' => $rid,
  1942. 'permission' => 'bypass node access',
  1943. ));
  1944. }
  1945. $insert->execute();
  1946. }
  1947. /**
  1948. * Convert default time zone offset to default time zone name.
  1949. */
  1950. function system_update_7013() {
  1951. $timezone = NULL;
  1952. $timezones = system_time_zones();
  1953. // If the contributed Date module set a default time zone name, use this
  1954. // setting as the default time zone.
  1955. if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) {
  1956. $timezone = $timezone_name;
  1957. }
  1958. // If the contributed Event module has set a default site time zone, look up
  1959. // the time zone name and use it as the default time zone.
  1960. if (!$timezone && ($timezone_id = variable_get('date_default_timezone_id', 0))) {
  1961. try {
  1962. $timezone_name = db_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField();
  1963. if (($timezone_name = str_replace(' ', '_', $timezone_name)) && isset($timezones[$timezone_name])) {
  1964. $timezone = $timezone_name;
  1965. }
  1966. }
  1967. catch (PDOException $e) {
  1968. // Ignore error if event_timezones table does not exist or unexpected
  1969. // schema found.
  1970. }
  1971. }
  1972. // Check to see if timezone was overriden in update_prepare_d7_bootstrap().
  1973. $offset = variable_get('date_temporary_timezone');
  1974. // If not, use the default.
  1975. if (!isset($offset)) {
  1976. $offset = variable_get('date_default_timezone', 0);
  1977. }
  1978. // If the previous default time zone was a non-zero offset, guess the site's
  1979. // intended time zone based on that offset and the server's daylight saving
  1980. // time status.
  1981. if (!$timezone && $offset) {
  1982. $timezone_name = timezone_name_from_abbr('', intval($offset), date('I'));
  1983. if ($timezone_name && isset($timezones[$timezone_name])) {
  1984. $timezone = $timezone_name;
  1985. }
  1986. }
  1987. // Otherwise, the default time zone offset was zero, which is UTC.
  1988. if (!$timezone) {
  1989. $timezone = 'UTC';
  1990. }
  1991. variable_set('date_default_timezone', $timezone);
  1992. drupal_set_message(format_string('The default time zone has been set to %timezone. Check the <a href="@config-url">date and time configuration page</a> to configure it correctly.', array('%timezone' => $timezone, '@config-url' => url('admin/config/regional/settings'))), 'warning');
  1993. // Remove temporary override.
  1994. variable_del('date_temporary_timezone');
  1995. }
  1996. /**
  1997. * Change the user logout path.
  1998. */
  1999. function system_update_7015() {
  2000. db_update('menu_links')
  2001. ->fields(array('link_path' => 'user/logout'))
  2002. ->condition('link_path', 'logout')
  2003. ->execute();
  2004. db_update('menu_links')
  2005. ->fields(array('router_path' => 'user/logout'))
  2006. ->condition('router_path', 'logout')
  2007. ->execute();
  2008. db_update('menu_links')
  2009. ->fields(array(
  2010. 'menu_name' => 'user-menu',
  2011. 'plid' => 0,
  2012. ))
  2013. ->condition(db_or()
  2014. ->condition('link_path', 'user/logout')
  2015. ->condition('router_path', 'user/logout')
  2016. )
  2017. ->condition('module', 'system')
  2018. ->condition('customized', 0)
  2019. ->execute();
  2020. }
  2021. /**
  2022. * Remove custom datatype *_unsigned in PostgreSQL.
  2023. */
  2024. function system_update_7016() {
  2025. // Only run these queries if the driver used is pgsql.
  2026. if (db_driver() == 'pgsql') {
  2027. $result = db_query("SELECT c.relname AS table, a.attname AS field,
  2028. pg_catalog.format_type(a.atttypid, a.atttypmod) AS type
  2029. FROM pg_catalog.pg_attribute a
  2030. LEFT JOIN pg_class c ON (c.oid = a.attrelid)
  2031. WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind = 'r'
  2032. AND pg_catalog.format_type(a.atttypid, a.atttypmod) LIKE '%unsigned%'");
  2033. foreach ($result as $row) {
  2034. switch ($row->type) {
  2035. case 'smallint_unsigned':
  2036. $datatype = 'int';
  2037. break;
  2038. case 'int_unsigned':
  2039. case 'bigint_unsigned':
  2040. default:
  2041. $datatype = 'bigint';
  2042. break;
  2043. }
  2044. db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN "' . $row->field . '" TYPE ' . $datatype);
  2045. db_query('ALTER TABLE ' . $row->table . ' ADD CHECK ("' . $row->field . '" >= 0)');
  2046. }
  2047. db_query('DROP DOMAIN IF EXISTS smallint_unsigned');
  2048. db_query('DROP DOMAIN IF EXISTS int_unsigned');
  2049. db_query('DROP DOMAIN IF EXISTS bigint_unsigned');
  2050. }
  2051. }
  2052. /**
  2053. * Change the theme setting 'toggle_node_info' into a per content type variable.
  2054. */
  2055. function system_update_7017() {
  2056. // Get the global theme settings.
  2057. $settings = variable_get('theme_settings', array());
  2058. // Get the settings of the default theme.
  2059. $settings = array_merge($settings, variable_get('theme_' . variable_get('theme_default', 'garland') . '_settings', array()));
  2060. $types = _update_7000_node_get_types();
  2061. foreach ($types as $type) {
  2062. if (isset($settings['toggle_node_info_' . $type->type])) {
  2063. variable_set('node_submitted_' . $type->type, $settings['toggle_node_info_' . $type->type]);
  2064. }
  2065. }
  2066. // Unset deprecated 'toggle_node_info' theme settings.
  2067. $theme_settings = variable_get('theme_settings', array());
  2068. foreach ($theme_settings as $setting => $value) {
  2069. if (substr($setting, 0, 16) == 'toggle_node_info') {
  2070. unset($theme_settings[$setting]);
  2071. }
  2072. }
  2073. variable_set('theme_settings', $theme_settings);
  2074. }
  2075. /**
  2076. * Shorten the {system}.type column and modify indexes.
  2077. */
  2078. function system_update_7018() {
  2079. db_drop_index('system', 'modules');
  2080. db_drop_index('system', 'type_name');
  2081. db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
  2082. db_add_index('system', 'type_name', array('type', 'name'));
  2083. }
  2084. /**
  2085. * Enable field and field_ui modules.
  2086. */
  2087. function system_update_7020() {
  2088. $module_list = array('field_sql_storage', 'field', 'field_ui');
  2089. module_enable($module_list, FALSE);
  2090. }
  2091. /**
  2092. * Change the PHP for settings permission.
  2093. */
  2094. function system_update_7021() {
  2095. db_update('role_permission')
  2096. ->fields(array('permission' => 'use PHP for settings'))
  2097. ->condition('permission', 'use PHP for block visibility')
  2098. ->execute();
  2099. }
  2100. /**
  2101. * Enable field type modules.
  2102. */
  2103. function system_update_7027() {
  2104. $module_list = array('text', 'number', 'list', 'options');
  2105. module_enable($module_list, FALSE);
  2106. }
  2107. /**
  2108. * Add new 'view own unpublished content' permission for authenticated users.
  2109. * Preserves legacy behavior from Drupal 6.x.
  2110. */
  2111. function system_update_7029() {
  2112. db_insert('role_permission')
  2113. ->fields(array(
  2114. 'rid' => DRUPAL_AUTHENTICATED_RID,
  2115. 'permission' => 'view own unpublished content',
  2116. ))
  2117. ->execute();
  2118. }
  2119. /**
  2120. * Alter field hostname to identifier in the {flood} table.
  2121. */
  2122. function system_update_7032() {
  2123. db_drop_index('flood', 'allow');
  2124. db_change_field('flood', 'hostname', 'identifier', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
  2125. db_add_index('flood', 'allow', array('event', 'identifier', 'timestamp'));
  2126. }
  2127. /**
  2128. * Move CACHE_AGGRESSIVE to CACHE_NORMAL.
  2129. */
  2130. function system_update_7033() {
  2131. if (variable_get('cache') == 2) {
  2132. variable_set('cache', 1);
  2133. return t('Aggressive caching was disabled and replaced with normal caching. Read the page caching section in default.settings.php for more information on how to enable similar functionality.');
  2134. }
  2135. }
  2136. /**
  2137. * Migrate the file path settings and create the new {file_managed} table.
  2138. */
  2139. function system_update_7034() {
  2140. $files_directory = variable_get('file_directory_path', NULL);
  2141. if (variable_get('file_downloads', 1) == 1) {
  2142. // Our default is public, so we don't need to set anything.
  2143. if (!empty($files_directory)) {
  2144. variable_set('file_public_path', $files_directory);
  2145. }
  2146. }
  2147. elseif (variable_get('file_downloads', 1) == 2) {
  2148. variable_set('file_default_scheme', 'private');
  2149. if (!empty($files_directory)) {
  2150. variable_set('file_private_path', $files_directory);
  2151. }
  2152. }
  2153. variable_del('file_downloads');
  2154. $schema['file_managed'] = array(
  2155. 'description' => 'Stores information for uploaded files.',
  2156. 'fields' => array(
  2157. 'fid' => array(
  2158. 'description' => 'File ID.',
  2159. 'type' => 'serial',
  2160. 'unsigned' => TRUE,
  2161. 'not null' => TRUE,
  2162. ),
  2163. 'uid' => array(
  2164. 'description' => 'The {user}.uid of the user who is associated with the file.',
  2165. 'type' => 'int',
  2166. 'unsigned' => TRUE,
  2167. 'not null' => TRUE,
  2168. 'default' => 0,
  2169. ),
  2170. 'filename' => array(
  2171. 'description' => 'Name of the file with no path components. This may differ from the basename of the filepath if the file is renamed to avoid overwriting an existing file.',
  2172. 'type' => 'varchar',
  2173. 'length' => 255,
  2174. 'not null' => TRUE,
  2175. 'default' => '',
  2176. 'binary' => TRUE,
  2177. ),
  2178. 'uri' => array(
  2179. 'description' => 'URI of file.',
  2180. 'type' => 'varchar',
  2181. 'length' => 255,
  2182. 'not null' => TRUE,
  2183. 'default' => '',
  2184. 'binary' => TRUE,
  2185. ),
  2186. 'filemime' => array(
  2187. 'description' => "The file's MIME type.",
  2188. 'type' => 'varchar',
  2189. 'length' => 255,
  2190. 'not null' => TRUE,
  2191. 'default' => '',
  2192. ),
  2193. 'filesize' => array(
  2194. 'description' => 'The size of the file in bytes.',
  2195. 'type' => 'int',
  2196. 'unsigned' => TRUE,
  2197. 'not null' => TRUE,
  2198. 'default' => 0,
  2199. ),
  2200. 'status' => array(
  2201. 'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
  2202. 'type' => 'int',
  2203. 'not null' => TRUE,
  2204. 'default' => 0,
  2205. 'size' => 'tiny',
  2206. ),
  2207. 'timestamp' => array(
  2208. 'description' => 'UNIX timestamp for when the file was added.',
  2209. 'type' => 'int',
  2210. 'unsigned' => TRUE,
  2211. 'not null' => TRUE,
  2212. 'default' => 0,
  2213. ),
  2214. ),
  2215. 'indexes' => array(
  2216. 'uid' => array('uid'),
  2217. 'status' => array('status'),
  2218. 'timestamp' => array('timestamp'),
  2219. ),
  2220. 'unique keys' => array(
  2221. 'uri' => array('uri'),
  2222. ),
  2223. 'primary key' => array('fid'),
  2224. );
  2225. db_create_table('file_managed', $schema['file_managed']);
  2226. }
  2227. /**
  2228. * Split the 'access site in maintenance mode' permission from 'administer site configuration'.
  2229. */
  2230. function system_update_7036() {
  2231. // Get existing roles that can 'administer site configuration'.
  2232. $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
  2233. // None found.
  2234. if (empty($rids)) {
  2235. return;
  2236. }
  2237. $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
  2238. foreach ($rids as $rid) {
  2239. $insert->values(array(
  2240. 'rid' => $rid,
  2241. 'permission' => 'access site in maintenance mode',
  2242. ));
  2243. }
  2244. $insert->execute();
  2245. }
  2246. /**
  2247. * Upgrade the {url_alias} table and create a cache bin for path aliases.
  2248. */
  2249. function system_update_7042() {
  2250. // update_fix_d7_requirements() adds 'fake' source and alias columns to
  2251. // allow bootstrap to run without fatal errors. Remove those columns now
  2252. // so that we can rename properly.
  2253. db_drop_field('url_alias', 'source');
  2254. db_drop_field('url_alias', 'alias');
  2255. // Drop indexes.
  2256. db_drop_index('url_alias', 'src_language_pid');
  2257. db_drop_unique_key('url_alias', 'dst_language_pid');
  2258. // Rename the fields, and increase their length to 255 characters.
  2259. db_change_field('url_alias', 'src', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  2260. db_change_field('url_alias', 'dst', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
  2261. // Add indexes back. We replace the unique key with an index since it never
  2262. // provided any meaningful unique constraint ('pid' is a primary key).
  2263. db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid'));
  2264. db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid'));
  2265. // Now that the URL aliases are correct, we can rebuild the whitelist.
  2266. drupal_path_alias_whitelist_rebuild();
  2267. }
  2268. /**
  2269. * Drop the actions_aid table.
  2270. */
  2271. function system_update_7044() {
  2272. // The current value of the increment has been taken into account when
  2273. // creating the sequences table in update_fix_d7_requirements().
  2274. db_drop_table('actions_aid');
  2275. }
  2276. /**
  2277. * Add expiration field to the {flood} table.
  2278. */
  2279. function system_update_7045() {
  2280. db_add_field('flood', 'expiration', array('description' => 'Expiration timestamp. Expired events are purged on cron run.', 'type' => 'int', 'not null' => TRUE, 'default' => 0));
  2281. db_add_index('flood', 'purge', array('expiration'));
  2282. }
  2283. /**
  2284. * Switch from the Minnelli theme if it is the default or admin theme.
  2285. */
  2286. function system_update_7046() {
  2287. if (variable_get('theme_default') == 'minnelli' || variable_get('admin_theme') == 'minnelli') {
  2288. // Make sure Garland is enabled.
  2289. db_update('system')
  2290. ->fields(array('status' => 1))
  2291. ->condition('type', 'theme')
  2292. ->condition('name', 'garland')
  2293. ->execute();
  2294. if (variable_get('theme_default') != 'garland') {
  2295. // If the default theme isn't Garland, transfer all of Minnelli's old
  2296. // settings to Garland.
  2297. $settings = variable_get('theme_minnelli_settings', array());
  2298. // Set the theme setting width to "fixed" to match Minnelli's old layout.
  2299. $settings['garland_width'] = 'fixed';
  2300. variable_set('theme_garland_settings', $settings);
  2301. // Remove Garland's color files since they won't match Minnelli's.
  2302. foreach (variable_get('color_garland_files', array()) as $file) {
  2303. @drupal_unlink($file);
  2304. }
  2305. if (isset($file) && $file = dirname($file)) {
  2306. @drupal_rmdir($file);
  2307. }
  2308. variable_del('color_garland_palette');
  2309. variable_del('color_garland_stylesheets');
  2310. variable_del('color_garland_logo');
  2311. variable_del('color_garland_files');
  2312. variable_del('color_garland_screenshot');
  2313. }
  2314. if (variable_get('theme_default') == 'minnelli') {
  2315. variable_set('theme_default', 'garland');
  2316. }
  2317. if (variable_get('admin_theme') == 'minnelli') {
  2318. variable_set('admin_theme', 'garland');
  2319. }
  2320. }
  2321. }
  2322. /**
  2323. * Normalize the front page path variable.
  2324. */
  2325. function system_update_7047() {
  2326. variable_set('site_frontpage', drupal_get_normal_path(variable_get('site_frontpage', 'node')));
  2327. }
  2328. /**
  2329. * Convert path languages from the empty string to LANGUAGE_NONE.
  2330. */
  2331. function system_update_7048() {
  2332. db_update('url_alias')
  2333. ->fields(array('language' => LANGUAGE_NONE))
  2334. ->condition('language', '')
  2335. ->execute();
  2336. }
  2337. /**
  2338. * Rename 'Default' profile to 'Standard.'
  2339. */
  2340. function system_update_7049() {
  2341. if (variable_get('install_profile', 'standard') == 'default') {
  2342. variable_set('install_profile', 'standard');
  2343. }
  2344. }
  2345. /**
  2346. * Change {batch}.id column from serial to regular int.
  2347. */
  2348. function system_update_7050() {
  2349. db_change_field('batch', 'bid', 'bid', array('description' => 'Primary Key: Unique batch ID.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
  2350. }
  2351. /**
  2352. * make the IP field IPv6 compatible
  2353. */
  2354. function system_update_7051() {
  2355. db_change_field('blocked_ips', 'ip', 'ip', array('description' => 'IP address', 'type' => 'varchar', 'length' => 40, 'not null' => TRUE, 'default' => ''));
  2356. }
  2357. /**
  2358. * Rename file to include_file in {menu_router} table.
  2359. */
  2360. function system_update_7052() {
  2361. db_change_field('menu_router', 'file', 'include_file', array('type' => 'text', 'size' => 'medium'));
  2362. }
  2363. /**
  2364. * Upgrade standard blocks and menus.
  2365. */
  2366. function system_update_7053() {
  2367. if (db_table_exists('menu_custom')) {
  2368. // Create the same menus as in menu_install().
  2369. db_insert('menu_custom')
  2370. ->fields(array('menu_name' => 'user-menu', 'title' => 'User Menu', 'description' => "The <em>User</em> menu contains links related to the user's account, as well as the 'Log out' link."))
  2371. ->execute();
  2372. db_insert('menu_custom')
  2373. ->fields(array('menu_name' => 'management', 'title' => 'Management', 'description' => "The <em>Management</em> menu contains links for administrative tasks."))
  2374. ->execute();
  2375. }
  2376. block_flush_caches();
  2377. // Show the new menu blocks along the navigation block.
  2378. $blocks = db_query("SELECT theme, status, region, weight, visibility, pages FROM {block} WHERE module = 'system' AND delta = 'navigation'");
  2379. $deltas = db_or()
  2380. ->condition('delta', 'user-menu')
  2381. ->condition('delta', 'management');
  2382. foreach ($blocks as $block) {
  2383. db_update('block')
  2384. ->fields(array(
  2385. 'status' => $block->status,
  2386. 'region' => $block->region,
  2387. 'weight' => $block->weight,
  2388. 'visibility' => $block->visibility,
  2389. 'pages' => $block->pages,
  2390. ))
  2391. ->condition('theme', $block->theme)
  2392. ->condition('module', 'system')
  2393. ->condition($deltas)
  2394. ->execute();
  2395. }
  2396. }
  2397. /**
  2398. * Remove {cache_*}.headers columns.
  2399. */
  2400. function system_update_7054() {
  2401. // Update: update_fix_d7_requirements() installs this version for cache_path
  2402. // already, so we don't include it in this particular update. It should be
  2403. // included in later updates though.
  2404. $cache_tables = array(
  2405. 'cache' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
  2406. 'cache_form' => 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.',
  2407. 'cache_page' => 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.',
  2408. 'cache_menu' => 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.',
  2409. );
  2410. $schema = system_schema_cache_7054();
  2411. foreach ($cache_tables as $table => $description) {
  2412. $schema['description'] = $description;
  2413. db_drop_table($table);
  2414. db_create_table($table, $schema);
  2415. }
  2416. }
  2417. /**
  2418. * Converts fields that store serialized variables from text to blob.
  2419. */
  2420. function system_update_7055() {
  2421. $spec = array(
  2422. 'description' => 'The value of the variable.',
  2423. 'type' => 'blob',
  2424. 'not null' => TRUE,
  2425. 'size' => 'big',
  2426. 'translatable' => TRUE,
  2427. );
  2428. db_change_field('variable', 'value', 'value', $spec);
  2429. $spec = array(
  2430. 'description' => 'Parameters to be passed to the callback function.',
  2431. 'type' => 'blob',
  2432. 'not null' => TRUE,
  2433. 'size' => 'big',
  2434. );
  2435. db_change_field('actions', 'parameters', 'parameters', $spec);
  2436. $spec = array(
  2437. 'description' => 'A serialized array containing the processing data for the batch.',
  2438. 'type' => 'blob',
  2439. 'not null' => FALSE,
  2440. 'size' => 'big',
  2441. );
  2442. db_change_field('batch', 'batch', 'batch', $spec);
  2443. $spec = array(
  2444. '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.',
  2445. 'type' => 'blob',
  2446. 'not null' => TRUE,
  2447. );
  2448. db_change_field('menu_router', 'load_functions', 'load_functions', $spec);
  2449. $spec = array(
  2450. '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.',
  2451. 'type' => 'blob',
  2452. 'not null' => TRUE,
  2453. );
  2454. db_change_field('menu_router', 'to_arg_functions', 'to_arg_functions', $spec);
  2455. $spec = array(
  2456. 'description' => 'A serialized array of arguments for the access callback.',
  2457. 'type' => 'blob',
  2458. 'not null' => FALSE,
  2459. );
  2460. db_change_field('menu_router', 'access_arguments', 'access_arguments', $spec);
  2461. $spec = array(
  2462. 'description' => 'A serialized array of arguments for the page callback.',
  2463. 'type' => 'blob',
  2464. 'not null' => FALSE,
  2465. );
  2466. db_change_field('menu_router', 'page_arguments', 'page_arguments', $spec);
  2467. $spec = array(
  2468. 'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',
  2469. 'type' => 'blob',
  2470. 'not null' => FALSE,
  2471. 'translatable' => TRUE,
  2472. );
  2473. db_change_field('menu_links', 'options', 'options', $spec);
  2474. $spec = array(
  2475. '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.',
  2476. 'type' => 'blob',
  2477. 'not null' => FALSE,
  2478. 'size' => 'big',
  2479. );
  2480. db_change_field('sessions', 'session', 'session', $spec);
  2481. $spec = array(
  2482. 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
  2483. 'type' => 'blob',
  2484. 'not null' => FALSE,
  2485. );
  2486. db_change_field('system', 'info', 'info', $spec);
  2487. }
  2488. /**
  2489. * Increase the size of session-ids.
  2490. */
  2491. function system_update_7057() {
  2492. $spec = array(
  2493. 'description' => "A session ID. The value is generated by PHP's Session API.",
  2494. 'type' => 'varchar',
  2495. 'length' => 128,
  2496. 'not null' => TRUE,
  2497. 'default' => '',
  2498. );
  2499. db_change_field('sessions', 'sid', 'sid', $spec);
  2500. }
  2501. /**
  2502. * Remove cron semaphore variable.
  2503. */
  2504. function system_update_7058() {
  2505. variable_del('cron_semaphore');
  2506. }
  2507. /**
  2508. * Create the {file_usage} table.
  2509. */
  2510. function system_update_7059() {
  2511. $spec = array(
  2512. 'description' => 'Track where a file is used.',
  2513. 'fields' => array(
  2514. 'fid' => array(
  2515. 'description' => 'File ID.',
  2516. 'type' => 'int',
  2517. 'unsigned' => TRUE,
  2518. 'not null' => TRUE,
  2519. ),
  2520. 'module' => array(
  2521. 'description' => 'The name of the module that is using the file.',
  2522. 'type' => 'varchar',
  2523. 'length' => 255,
  2524. 'not null' => TRUE,
  2525. 'default' => '',
  2526. ),
  2527. 'type' => array(
  2528. 'description' => 'The name of the object type in which the file is used.',
  2529. 'type' => 'varchar',
  2530. 'length' => 64,
  2531. 'not null' => TRUE,
  2532. 'default' => '',
  2533. ),
  2534. 'id' => array(
  2535. 'description' => 'The primary key of the object using the file.',
  2536. 'type' => 'int',
  2537. 'unsigned' => TRUE,
  2538. 'not null' => TRUE,
  2539. 'default' => 0,
  2540. ),
  2541. 'count' => array(
  2542. 'description' => 'The number of times this file is used by this object.',
  2543. 'type' => 'int',
  2544. 'unsigned' => TRUE,
  2545. 'not null' => TRUE,
  2546. 'default' => 0,
  2547. ),
  2548. ),
  2549. 'primary key' => array('fid', 'type', 'id', 'module'),
  2550. 'indexes' => array(
  2551. 'type_id' => array('type', 'id'),
  2552. 'fid_count' => array('fid', 'count'),
  2553. 'fid_module' => array('fid', 'module'),
  2554. ),
  2555. );
  2556. db_create_table('file_usage', $spec);
  2557. }
  2558. /**
  2559. * Create fields in preparation for migrating upload.module to file.module.
  2560. */
  2561. function system_update_7060() {
  2562. if (!db_table_exists('upload')) {
  2563. return;
  2564. }
  2565. if (!db_query_range('SELECT 1 FROM {upload}', 0, 1)->fetchField()) {
  2566. // There is nothing to migrate. Delete variables and the empty table. There
  2567. // is no need to create fields that are not going to be used.
  2568. foreach (_update_7000_node_get_types() as $node_type) {
  2569. variable_del('upload_' . $node_type->type);
  2570. }
  2571. db_drop_table('upload');
  2572. return;
  2573. }
  2574. // Check which node types have upload.module attachments enabled.
  2575. $context['types'] = array();
  2576. foreach (_update_7000_node_get_types() as $node_type) {
  2577. if (variable_get('upload_' . $node_type->type, 0)) {
  2578. $context['types'][$node_type->type] = $node_type->type;
  2579. }
  2580. }
  2581. // The {upload} table will be deleted when this update is complete so we
  2582. // want to be careful to migrate all the data, even for node types that
  2583. // may have had attachments disabled after files were uploaded. Look for
  2584. // any other node types referenced by the upload records and add those to
  2585. // the list. The admin can always remove the field later.
  2586. $results = db_query('SELECT DISTINCT type FROM {node} n INNER JOIN {node_revision} nr ON n.nid = nr.nid INNER JOIN {upload} u ON nr.vid = u.vid');
  2587. foreach ($results as $row) {
  2588. if (!isset($context['types'][$row->type])) {
  2589. drupal_set_message(t('The content type %rowtype had uploads disabled but contained uploaded file data. Uploads have been re-enabled to migrate the existing data. You may delete the "File attachments" field in the %rowtype type if this data is not necessary.', array('%rowtype' => $row->type)));
  2590. $context['types'][$row->type] = $row->type;
  2591. }
  2592. }
  2593. // Create a single "upload" field on all the content types that have uploads
  2594. // enabled, then add an instance to each enabled type.
  2595. if (count($context['types']) > 0) {
  2596. module_enable(array('file'));
  2597. $field = array(
  2598. 'field_name' => 'upload',
  2599. 'type' => 'file',
  2600. 'module' => 'file',
  2601. 'locked' => FALSE,
  2602. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2603. 'translatable' => FALSE,
  2604. 'settings' => array(
  2605. 'display_field' => 1,
  2606. 'display_default' => variable_get('upload_list_default', 1),
  2607. 'uri_scheme' => file_default_scheme(),
  2608. 'default_file' => 0,
  2609. ),
  2610. );
  2611. $upload_size = variable_get('upload_uploadsize_default', 1);
  2612. $instance = array(
  2613. 'field_name' => 'upload',
  2614. 'entity_type' => 'node',
  2615. 'bundle' => NULL,
  2616. 'label' => 'File attachments',
  2617. 'required' => 0,
  2618. 'description' => '',
  2619. 'widget' => array(
  2620. 'weight' => '1',
  2621. 'settings' => array(
  2622. 'progress_indicator' => 'throbber',
  2623. ),
  2624. 'type' => 'file_generic',
  2625. ),
  2626. 'settings' => array(
  2627. 'max_filesize' => $upload_size ? ($upload_size . ' MB') : '',
  2628. 'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'),
  2629. 'file_directory' => '',
  2630. 'description_field' => 1,
  2631. ),
  2632. 'display' => array(
  2633. 'default' => array(
  2634. 'label' => 'hidden',
  2635. 'type' => 'file_table',
  2636. 'settings' => array(),
  2637. 'weight' => 0,
  2638. 'module' => 'file',
  2639. ),
  2640. 'full' => array(
  2641. 'label' => 'hidden',
  2642. 'type' => 'file_table',
  2643. 'settings' => array(),
  2644. 'weight' => 0,
  2645. 'module' => 'file',
  2646. ),
  2647. 'teaser' => array(
  2648. 'label' => 'hidden',
  2649. 'type' => 'hidden',
  2650. 'settings' => array(),
  2651. 'weight' => 0,
  2652. 'module' => NULL,
  2653. ),
  2654. 'rss' => array(
  2655. 'label' => 'hidden',
  2656. 'type' => 'file_table',
  2657. 'settings' => array(),
  2658. 'weight' => 0,
  2659. 'module' => 'file',
  2660. ),
  2661. ),
  2662. );
  2663. // Create the field.
  2664. _update_7000_field_create_field($field);
  2665. // Create the instances.
  2666. foreach ($context['types'] as $bundle) {
  2667. $instance['bundle'] = $bundle;
  2668. _update_7000_field_create_instance($field, $instance);
  2669. // Now that the instance is created, we can safely delete any legacy
  2670. // node type information.
  2671. variable_del('upload_' . $bundle);
  2672. }
  2673. }
  2674. else {
  2675. // No uploads or content types with uploads enabled.
  2676. db_drop_table('upload');
  2677. }
  2678. }
  2679. /**
  2680. * Migrate upload.module data to the newly created file field.
  2681. */
  2682. function system_update_7061(&$sandbox) {
  2683. if (!db_table_exists('upload')) {
  2684. return;
  2685. }
  2686. if (!isset($sandbox['progress'])) {
  2687. // Delete stale rows from {upload} where the fid is not in the {files} table.
  2688. db_delete('upload')
  2689. ->notExists(
  2690. db_select('files', 'f')
  2691. ->fields('f', array('fid'))
  2692. ->where('f.fid = {upload}.fid')
  2693. )
  2694. ->execute();
  2695. // Delete stale rows from {upload} where the vid is not in the
  2696. // {node_revision} table. The table has already been renamed in
  2697. // node_update_7001().
  2698. db_delete('upload')
  2699. ->notExists(
  2700. db_select('node_revision', 'nr')
  2701. ->fields('nr', array('vid'))
  2702. ->where('nr.vid = {upload}.vid')
  2703. )
  2704. ->execute();
  2705. // Retrieve a list of node revisions that have uploaded files attached.
  2706. // DISTINCT queries are expensive, especially when paged, so we store the
  2707. // data in its own table for the duration of the update.
  2708. if (!db_table_exists('system_update_7061')) {
  2709. $table = array(
  2710. 'description' => t('Stores temporary data for system_update_7061.'),
  2711. 'fields' => array('vid' => array('type' => 'int', 'not null' => TRUE)),
  2712. 'primary key' => array('vid'),
  2713. );
  2714. db_create_table('system_update_7061', $table);
  2715. }
  2716. $query = db_select('upload', 'u');
  2717. $query->distinct();
  2718. $query->addField('u','vid');
  2719. db_insert('system_update_7061')
  2720. ->from($query)
  2721. ->execute();
  2722. // Retrieve a list of duplicate files with the same filepath. Only the
  2723. // most-recently uploaded of these will be moved to the new {file_managed}
  2724. // table (and all references will be updated to point to it), since
  2725. // duplicate file URIs are not allowed in Drupal 7.
  2726. // Since the Drupal 6 to 7 upgrade path leaves the {files} table behind
  2727. // after it's done, custom or contributed modules which need to migrate
  2728. // file references of their own can use a similar query to determine the
  2729. // file IDs that duplicate filepaths were mapped to.
  2730. $sandbox['duplicate_filepath_fids_to_use'] = db_query("SELECT filepath, MAX(fid) FROM {files} GROUP BY filepath HAVING COUNT(*) > 1")->fetchAllKeyed();
  2731. // Initialize batch update information.
  2732. $sandbox['progress'] = 0;
  2733. $sandbox['last_vid_processed'] = -1;
  2734. $sandbox['max'] = db_query("SELECT COUNT(*) FROM {system_update_7061}")->fetchField();
  2735. }
  2736. // Determine vids for this batch.
  2737. // Process all files attached to a given revision during the same batch.
  2738. $limit = variable_get('upload_update_batch_size', 100);
  2739. $vids = db_query_range('SELECT vid FROM {system_update_7061} WHERE vid > :lastvid ORDER BY vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']))
  2740. ->fetchCol();
  2741. // Retrieve information on all the files attached to these revisions.
  2742. if (!empty($vids)) {
  2743. $node_revisions = array();
  2744. $result = db_query('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type, u.weight FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight, u.fid', array(':vids' => $vids));
  2745. foreach ($result as $record) {
  2746. // For each uploaded file, retrieve the corresponding data from the old
  2747. // files table (since upload doesn't know about the new entry in the
  2748. // file_managed table).
  2749. $file = db_select('files', 'f')
  2750. ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
  2751. ->condition('f.fid', $record->fid)
  2752. ->execute()
  2753. ->fetchAssoc();
  2754. if (!$file) {
  2755. continue;
  2756. }
  2757. // If this file has a duplicate filepath, replace it with the
  2758. // most-recently uploaded file that has the same filepath.
  2759. if (isset($sandbox['duplicate_filepath_fids_to_use'][$file['filepath']]) && $record->fid != $sandbox['duplicate_filepath_fids_to_use'][$file['filepath']]) {
  2760. $file = db_select('files', 'f')
  2761. ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
  2762. ->condition('f.fid', $sandbox['duplicate_filepath_fids_to_use'][$file['filepath']])
  2763. ->execute()
  2764. ->fetchAssoc();
  2765. }
  2766. // Add in the file information from the upload table.
  2767. $file['description'] = $record->description;
  2768. $file['display'] = $record->list;
  2769. // Create one record for each revision that contains all the uploaded
  2770. // files.
  2771. $node_revisions[$record->vid]['nid'] = $record->nid;
  2772. $node_revisions[$record->vid]['vid'] = $record->vid;
  2773. $node_revisions[$record->vid]['type'] = $record->type;
  2774. $node_revisions[$record->vid]['file'][LANGUAGE_NONE][] = $file;
  2775. }
  2776. // Now that we know which files belong to which revisions, update the
  2777. // files'// database entries, and save a reference to each file in the
  2778. // upload field on their node revisions.
  2779. $basename = variable_get('file_directory_path', conf_path() . '/files');
  2780. $scheme = file_default_scheme() . '://';
  2781. foreach ($node_revisions as $vid => $revision) {
  2782. foreach ($revision['file'][LANGUAGE_NONE] as $delta => $file) {
  2783. // We will convert filepaths to URI using the default scheme
  2784. // and stripping off the existing file directory path.
  2785. $file['uri'] = $scheme . preg_replace('!^' . preg_quote($basename) . '!', '', $file['filepath']);
  2786. // Normalize the URI but don't call file_stream_wrapper_uri_normalize()
  2787. // directly, since that is a higher-level API function which invokes
  2788. // hooks while validating the scheme, and those will not work during
  2789. // the upgrade. Instead, use a simpler version that just assumes the
  2790. // scheme from above is already valid.
  2791. if (($file_uri_scheme = file_uri_scheme($file['uri'])) && ($file_uri_target = file_uri_target($file['uri']))) {
  2792. $file['uri'] = $file_uri_scheme . '://' . $file_uri_target;
  2793. }
  2794. unset($file['filepath']);
  2795. // Insert into the file_managed table.
  2796. // Each fid should only be stored once in file_managed.
  2797. db_merge('file_managed')
  2798. ->key(array(
  2799. 'fid' => $file['fid'],
  2800. ))
  2801. ->fields(array(
  2802. 'uid' => $file['uid'],
  2803. 'filename' => $file['filename'],
  2804. 'uri' => $file['uri'],
  2805. 'filemime' => $file['filemime'],
  2806. 'filesize' => $file['filesize'],
  2807. 'status' => $file['status'],
  2808. 'timestamp' => $file['timestamp'],
  2809. ))
  2810. ->execute();
  2811. // Add the usage entry for the file.
  2812. $file = (object) $file;
  2813. file_usage_add($file, 'file', 'node', $revision['nid']);
  2814. // Update the node revision's upload file field with the file data.
  2815. $revision['file'][LANGUAGE_NONE][$delta] = array('fid' => $file->fid, 'display' => $file->display, 'description' => $file->description);
  2816. }
  2817. // Write the revision's upload field data into the field_upload tables.
  2818. $node = (object) $revision;
  2819. _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'upload', $node->file);
  2820. // Update our progress information for the batch update.
  2821. $sandbox['progress']++;
  2822. $sandbox['last_vid_processed'] = $vid;
  2823. }
  2824. }
  2825. // If less than limit node revisions were processed, the update process is
  2826. // finished.
  2827. if (count($vids) < $limit) {
  2828. $finished = TRUE;
  2829. }
  2830. // If there's no max value then there's nothing to update and we're finished.
  2831. if (empty($sandbox['max']) || isset($finished)) {
  2832. db_drop_table('upload');
  2833. db_drop_table('system_update_7061');
  2834. return t('Upload module has been migrated to File module.');
  2835. }
  2836. else {
  2837. // Indicate our current progress to the batch update system.
  2838. $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  2839. }
  2840. }
  2841. /**
  2842. * Replace 'system_list' index with 'bootstrap' index on {system}.
  2843. */
  2844. function system_update_7062() {
  2845. db_drop_index('system', 'bootstrap');
  2846. db_drop_index('system', 'system_list');
  2847. db_add_index('system', 'system_list', array('status', 'bootstrap', 'type', 'weight', 'name'));
  2848. }
  2849. /**
  2850. * Delete {menu_links} records for 'type' => MENU_CALLBACK which would not appear in a fresh install.
  2851. */
  2852. function system_update_7063() {
  2853. // For router items where 'type' => MENU_CALLBACK, {menu_router}.type is
  2854. // stored as 4 in Drupal 6, and 0 in Drupal 7. Fortunately Drupal 7 doesn't
  2855. // store any types as 4, so delete both.
  2856. $result = db_query('SELECT ml.mlid FROM {menu_links} ml INNER JOIN {menu_router} mr ON ml.router_path = mr.path WHERE ml.module = :system AND ml.customized = 0 AND mr.type IN(:callbacks)', array(':callbacks' => array(0, 4), ':system' => 'system'));
  2857. foreach ($result as $record) {
  2858. db_delete('menu_links')->condition('mlid', $record->mlid)->execute();
  2859. }
  2860. }
  2861. /**
  2862. * Remove block_callback field from {menu_router}.
  2863. */
  2864. function system_update_7064() {
  2865. db_drop_field('menu_router', 'block_callback');
  2866. }
  2867. /**
  2868. * Remove the default value for sid.
  2869. */
  2870. function system_update_7065() {
  2871. $spec = array(
  2872. 'description' => "A session ID. The value is generated by Drupal's session handlers.",
  2873. 'type' => 'varchar',
  2874. 'length' => 128,
  2875. 'not null' => TRUE,
  2876. );
  2877. db_drop_primary_key('sessions');
  2878. db_change_field('sessions', 'sid', 'sid', $spec, array('primary key' => array('sid', 'ssid')));
  2879. // Delete any sessions with empty session ID.
  2880. db_delete('sessions')->condition('sid', '')->execute();
  2881. }
  2882. /**
  2883. * Migrate the 'file_directory_temp' variable.
  2884. */
  2885. function system_update_7066() {
  2886. $d6_file_directory_temp = variable_get('file_directory_temp', file_directory_temp());
  2887. variable_set('file_temporary_path', $d6_file_directory_temp);
  2888. variable_del('file_directory_temp');
  2889. }
  2890. /**
  2891. * Grant administrators permission to view the administration theme.
  2892. */
  2893. function system_update_7067() {
  2894. // Users with access to administration pages already see the administration
  2895. // theme in some places (if one is enabled on the site), so we want them to
  2896. // continue seeing it.
  2897. $admin_roles = user_roles(FALSE, 'access administration pages');
  2898. foreach (array_keys($admin_roles) as $rid) {
  2899. _update_7000_user_role_grant_permissions($rid, array('view the administration theme'), 'system');
  2900. }
  2901. // The above check is not guaranteed to reach all administrative users of the
  2902. // site, so if the site is currently using an administration theme, display a
  2903. // message also.
  2904. if (variable_get('admin_theme')) {
  2905. if (empty($admin_roles)) {
  2906. drupal_set_message('The new "View the administration theme" permission is required in order to view your site\'s administration theme. You can grant this permission to your site\'s administrators on the <a href="' . url('admin/people/permissions', array('fragment' => 'module-system')) . '">permissions page</a>.');
  2907. }
  2908. else {
  2909. drupal_set_message('The new "View the administration theme" permission is required in order to view your site\'s administration theme. This permission has been automatically granted to the following roles: <em>' . check_plain(implode(', ', $admin_roles)) . '</em>. You can grant this permission to other roles on the <a href="' . url('admin/people/permissions', array('fragment' => 'module-system')) . '">permissions page</a>.');
  2910. }
  2911. }
  2912. }
  2913. /**
  2914. * Update {url_alias}.language description.
  2915. */
  2916. function system_update_7068() {
  2917. $spec = array(
  2918. 'description' => "The language 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.",
  2919. 'type' => 'varchar',
  2920. 'length' => 12,
  2921. 'not null' => TRUE,
  2922. 'default' => '',
  2923. );
  2924. db_change_field('url_alias', 'language', 'language', $spec);
  2925. }
  2926. /**
  2927. * Remove the obsolete 'site_offline' variable.
  2928. *
  2929. * @see update_fix_d7_requirements()
  2930. */
  2931. function system_update_7069() {
  2932. variable_del('site_offline');
  2933. }
  2934. /**
  2935. * @} End of "defgroup updates-6.x-to-7.x".
  2936. * The next series of updates should start at 8000.
  2937. */
  2938. /**
  2939. * @defgroup updates-7.x-extra Extra updates for 7.x
  2940. * @{
  2941. * Update functions between 7.x versions.
  2942. */
  2943. /**
  2944. * Remove the obsolete 'drupal_badge_color' and 'drupal_badge_size' variables.
  2945. */
  2946. function system_update_7070() {
  2947. variable_del('drupal_badge_color');
  2948. variable_del('drupal_badge_size');
  2949. }
  2950. /**
  2951. * Add index missed during upgrade, and fix field default.
  2952. */
  2953. function system_update_7071() {
  2954. db_drop_index('date_format_type', 'title');
  2955. db_add_index('date_format_type', 'title', array('title'));
  2956. db_change_field('registry', 'filename', 'filename', array(
  2957. 'type' => 'varchar',
  2958. 'length' => 255,
  2959. 'not null' => TRUE,
  2960. ));
  2961. }
  2962. /**
  2963. * Remove the obsolete 'site_offline_message' variable.
  2964. *
  2965. * @see update_fix_d7_requirements()
  2966. */
  2967. function system_update_7072() {
  2968. variable_del('site_offline_message');
  2969. }
  2970. /**
  2971. * Add binary to {file_managed}, in case system_update_7034() was run without
  2972. * it.
  2973. */
  2974. function system_update_7073() {
  2975. db_change_field('file_managed', 'filename', 'filename', array(
  2976. 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
  2977. 'type' => 'varchar',
  2978. 'length' => 255,
  2979. 'not null' => TRUE,
  2980. 'default' => '',
  2981. 'binary' => TRUE,
  2982. ));
  2983. db_drop_unique_key('file_managed', 'uri');
  2984. db_change_field('file_managed', 'uri', 'uri', array(
  2985. 'description' => 'The URI to access the file (either local or remote).',
  2986. 'type' => 'varchar',
  2987. 'length' => 255,
  2988. 'not null' => TRUE,
  2989. 'default' => '',
  2990. 'binary' => TRUE,
  2991. ));
  2992. db_add_unique_key('file_managed', 'uri', array('uri'));
  2993. }
  2994. /**
  2995. * This update has been removed and will not run.
  2996. */
  2997. function system_update_7074() {
  2998. // This update function previously converted menu_links query strings to
  2999. // arrays. It has been removed for now due to incompatibility with
  3000. // PostgreSQL.
  3001. }
  3002. /**
  3003. * Convert menu_links query strings into arrays.
  3004. */
  3005. function system_update_7076() {
  3006. $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC))
  3007. ->fields('ml', array('mlid', 'options'));
  3008. foreach ($query->execute() as $menu_link) {
  3009. if (strpos($menu_link['options'], 'query') !== FALSE) {
  3010. $menu_link['options'] = unserialize($menu_link['options']);
  3011. if (isset($menu_link['options']['query']) && is_string($menu_link['options']['query'])) {
  3012. $menu_link['options']['query'] = drupal_get_query_array($menu_link['options']['query']);
  3013. db_update('menu_links')
  3014. ->fields(array(
  3015. 'options' => serialize($menu_link['options']),
  3016. ))
  3017. ->condition('mlid', $menu_link['mlid'], '=')
  3018. ->execute();
  3019. }
  3020. }
  3021. }
  3022. }
  3023. /**
  3024. * Revert {file_managed}.filename changed to a binary column.
  3025. */
  3026. function system_update_7077() {
  3027. db_change_field('file_managed', 'filename', 'filename', array(
  3028. 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
  3029. 'type' => 'varchar',
  3030. 'length' => 255,
  3031. 'not null' => TRUE,
  3032. 'default' => '',
  3033. ));
  3034. }
  3035. /**
  3036. * Add binary to {date_formats}.format.
  3037. */
  3038. function system_update_7078() {
  3039. db_drop_unique_key('date_formats', 'formats');
  3040. db_change_field('date_formats', 'format', 'format', array(
  3041. 'description' => 'The date format string.',
  3042. 'type' => 'varchar',
  3043. 'length' => 100,
  3044. 'not null' => TRUE,
  3045. 'binary' => TRUE,
  3046. ), array('unique keys' => array('formats' => array('format', 'type'))));
  3047. }
  3048. /**
  3049. * Convert the 'filesize' column in {file_managed} to a bigint.
  3050. */
  3051. function system_update_7079() {
  3052. $spec = array(
  3053. 'description' => 'The size of the file in bytes.',
  3054. 'type' => 'int',
  3055. 'size' => 'big',
  3056. 'unsigned' => TRUE,
  3057. 'not null' => TRUE,
  3058. 'default' => 0,
  3059. );
  3060. db_change_field('file_managed', 'filesize', 'filesize', $spec);
  3061. }
  3062. /**
  3063. * Convert the 'format' column in {date_format_locale} to case sensitive varchar.
  3064. */
  3065. function system_update_7080() {
  3066. $spec = array(
  3067. 'description' => 'The date format string.',
  3068. 'type' => 'varchar',
  3069. 'length' => 100,
  3070. 'not null' => TRUE,
  3071. 'binary' => TRUE,
  3072. );
  3073. db_change_field('date_format_locale', 'format', 'format', $spec);
  3074. }
  3075. /**
  3076. * Remove the Drupal 6 default install profile if it is still in the database.
  3077. */
  3078. function system_update_7081() {
  3079. // Sites which used the default install profile in Drupal 6 and then updated
  3080. // to Drupal 7.44 or earlier will still have a record of this install profile
  3081. // in the database that needs to be deleted.
  3082. db_delete('system')
  3083. ->condition('filename', 'profiles/default/default.profile')
  3084. ->condition('type', 'module')
  3085. ->condition('status', 0)
  3086. ->condition('schema_version', 0)
  3087. ->execute();
  3088. }
  3089. /**
  3090. * Add 'jquery-extend-3.4.0.js' to the 'jquery' library.
  3091. */
  3092. function system_update_7082() {
  3093. // Empty update to force a rebuild of hook_library() and JS aggregates.
  3094. }
  3095. /**
  3096. * Add 'jquery-html-prefilter-3.5.0-backport.js' to the 'jquery' library.
  3097. */
  3098. function system_update_7083() {
  3099. // Empty update to force a rebuild of hook_library() and JS aggregates.
  3100. }
  3101. /**
  3102. * Rebuild JavaScript aggregates to include 'ajax.js' fix for Chrome 83.
  3103. */
  3104. function system_update_7084() {
  3105. // Empty update to force a rebuild of JS aggregates.
  3106. }
  3107. /**
  3108. * @} End of "defgroup updates-7.x-extra".
  3109. * The next series of updates should start at 8000.
  3110. */