system.install 114 KB

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