l10n_update.install 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. /**
  3. * @file
  4. * Install file for l10n remote updates.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function l10n_update_schema() {
  10. $schema['l10n_update_project'] = array(
  11. 'description' => 'Update information for project translations.',
  12. 'fields' => array(
  13. 'name' => array(
  14. 'description' => 'A unique short name to identify the project.',
  15. 'type' => 'varchar',
  16. 'length' => '255',
  17. 'not null' => TRUE,
  18. ),
  19. 'project_type' => array(
  20. 'description' => 'Project type, may be core, module, theme',
  21. 'type' => 'varchar',
  22. 'length' => '50',
  23. 'not null' => TRUE,
  24. ),
  25. 'core' => array(
  26. 'description' => 'Core compatibility string for this project.',
  27. 'type' => 'varchar',
  28. 'length' => '128',
  29. 'not null' => TRUE,
  30. 'default' => '',
  31. ),
  32. 'version' => array(
  33. 'description' => 'Human readable name for project used on the interface.',
  34. 'type' => 'varchar',
  35. 'length' => '128',
  36. 'not null' => TRUE,
  37. 'default' => '',
  38. ),
  39. 'l10n_server' => array(
  40. 'description' => 'Localization server for this project.',
  41. 'type' => 'varchar',
  42. 'length' => '255',
  43. 'not null' => TRUE,
  44. 'default' => '',
  45. ),
  46. 'l10n_path' => array(
  47. 'description' => 'Server path this project updates.',
  48. 'type' => 'varchar',
  49. 'length' => '255',
  50. 'not null' => TRUE,
  51. 'default' => '',
  52. ),
  53. 'status' => array(
  54. 'description' => 'Status flag. TBD',
  55. 'type' => 'int',
  56. 'not null' => TRUE,
  57. 'default' => 1,
  58. ),
  59. ),
  60. 'primary key' => array('name'),
  61. );
  62. $schema['l10n_update_file'] = array(
  63. 'description' => 'File and download information for project translations.',
  64. 'fields' => array(
  65. 'project' => array(
  66. 'description' => 'A unique short name to identify the project.',
  67. 'type' => 'varchar',
  68. 'length' => '255',
  69. 'not null' => TRUE,
  70. ),
  71. 'language' => array(
  72. 'description' => 'Reference to the {languages}.language for this translation.',
  73. 'type' => 'varchar',
  74. 'length' => '12',
  75. 'not null' => TRUE,
  76. ),
  77. 'type' => array(
  78. 'description' => 'File origin: download or localfile',
  79. 'type' => 'varchar',
  80. 'length' => '50',
  81. 'not null' => TRUE,
  82. 'default' => '',
  83. ),
  84. 'filename' => array(
  85. 'description' => 'Link to translation file for download.',
  86. 'type' => 'varchar',
  87. 'length' => 255,
  88. 'not null' => TRUE,
  89. 'default' => '',
  90. ),
  91. 'fileurl' => array(
  92. 'description' => 'Link to translation file for download.',
  93. 'type' => 'varchar',
  94. 'length' => 255,
  95. 'not null' => TRUE,
  96. 'default' => '',
  97. ),
  98. 'uri' => array(
  99. 'description' => 'File system path for importing the file.',
  100. 'type' => 'varchar',
  101. 'length' => 255,
  102. 'not null' => TRUE,
  103. 'default' => '',
  104. ),
  105. 'timestamp' => array(
  106. 'description' => 'Unix timestamp of the time the file was downloaded or saved to disk. Zero if not yet downloaded',
  107. 'type' => 'int',
  108. 'not null' => FALSE,
  109. 'disp-width' => '11',
  110. 'default' => 0,
  111. ),
  112. 'version' => array(
  113. 'description' => 'Version tag of the downloaded file.',
  114. 'type' => 'varchar',
  115. 'length' => '128',
  116. 'not null' => TRUE,
  117. 'default' => '',
  118. ),
  119. 'status' => array(
  120. 'description' => 'Status flag. TBD',
  121. 'type' => 'int',
  122. 'not null' => TRUE,
  123. 'default' => 1,
  124. ),
  125. 'last_checked' => array(
  126. 'description' => 'Unix timestamp of the last time this translation was downloaded from or checked at remote server and confirmed to be the most recent release available.',
  127. 'type' => 'int',
  128. 'not null' => FALSE,
  129. 'disp-width' => '11',
  130. 'default' => 0,
  131. ),
  132. ),
  133. 'primary key' => array('project', 'language'),
  134. );
  135. $schema['cache_l10n_update'] = drupal_get_schema_unprocessed('system', 'cache');
  136. $schema['cache_l10n_update']['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
  137. return $schema;
  138. }
  139. /**
  140. * Implements hook_schema_alter().
  141. */
  142. function l10n_update_schema_alter(&$schema) {
  143. $schema['locales_target']['fields']['l10n_status'] = array(
  144. 'type' => 'int',
  145. 'not null' => TRUE,
  146. 'default' => 0,
  147. );
  148. }
  149. /**
  150. * Implements hook_install().
  151. */
  152. function l10n_update_install() {
  153. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  154. variable_set('l10n_update_rebuild_projects', 1);
  155. }
  156. /**
  157. * Implements hook_uninstall().
  158. */
  159. function l10n_update_uninstall() {
  160. db_drop_field('locales_target', 'l10n_status');
  161. variable_del('l10n_update_check_disabled');
  162. variable_del('l10n_update_check_frequency');
  163. variable_del('l10n_update_check_mode');
  164. variable_del('l10n_update_default_server');
  165. variable_del('l10n_update_default_update_url');
  166. variable_del('l10n_update_download_store');
  167. variable_del('l10n_update_import_mode');
  168. variable_del('l10n_update_rebuild_projects');
  169. }
  170. /**
  171. * Implements hook_requirements().
  172. */
  173. function l10n_update_requirements($phase) {
  174. if ($phase == 'runtime') {
  175. $requirements['l10n_update']['title'] = t('Translation update status');
  176. if (variable_get('l10n_update_check_frequency', 0)) {
  177. if (l10n_update_get_projects() && l10n_update_language_list()) {
  178. if (l10n_update_available_updates()) {
  179. $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
  180. $requirements['l10n_update']['value'] = t('There are available updates');
  181. $requirements['l10n_update']['description'] = t('There are new or updated translations available for currently installed modules and themes. To check for updates, you can visit the <a href="@check_manually">translation update page</a>.', array(
  182. '@check_manually' => url('admin/config/regional/translate/update')
  183. ));
  184. }
  185. else {
  186. $requirements['l10n_update']['severity'] = REQUIREMENT_OK;
  187. $requirements['l10n_update']['value'] = t('All your translations are up to date');
  188. }
  189. }
  190. else {
  191. $requirements['l10n_update']['value'] = t('No update data available');
  192. $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
  193. $requirements['l10n_update']['description'] = _l10n_update_no_data();
  194. }
  195. }
  196. else {
  197. $requirements['l10n_update']['value'] = t('Not enabled');
  198. $requirements['l10n_update']['severity'] = REQUIREMENT_INFO;
  199. }
  200. // Test the contents of the .htaccess file in the translations directory.
  201. $directory = variable_get('l10n_update_download_store', '');
  202. if ($directory) {
  203. l10n_update_ensure_htaccess();
  204. $htaccess_file = $directory . '/.htaccess';
  205. // Check for the string which was added to the recommended .htaccess file
  206. // in the latest security update.
  207. if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
  208. $requirements['l10n_update_htaccess'] = array(
  209. 'title' => t('Translations directory'),
  210. 'value' => t('Not fully protected'),
  211. 'severity' => REQUIREMENT_ERROR,
  212. '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(
  213. '@url' => 'http://drupal.org/SA-CORE-2013-003',
  214. '%directory' => $directory
  215. )),
  216. );
  217. }
  218. }
  219. return $requirements;
  220. }
  221. // We must always return array, the installer doesn't use module_invoke_all()
  222. return array();
  223. }
  224. /**
  225. * Add status field to locales_target.
  226. */
  227. function l10n_update_update_6001() {
  228. if (!db_field_exists('locales_target', 'l10n_status')) {
  229. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  230. }
  231. return t('Added l10n_status field to locales_target.');
  232. }
  233. /**
  234. * Change status field name to l10n_status.
  235. */
  236. function l10n_update_update_6002() {
  237. // I18n Strings module adds a 'status' column to 'locales_target' table.
  238. // L10n Update module previously added a column with the same name. To avoid
  239. // any collision we change the column name here, but only if it was added by
  240. // L10n Update module.
  241. if (!db_field_exists('locales_target', 'l10n_status') && db_field_exists('locales_target', 'status') && !db_table_exists('i18n_strings')) {
  242. db_change_field('locales_target', 'status', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  243. }
  244. // Just in case someone did install I18n Strings, we still need to make sure
  245. // the 'l10n_status' column gets created.
  246. elseif (!db_field_exists('locales_target', 'l10n_status')) {
  247. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  248. }
  249. return t('Resolved possible l10n_status field conflict in locales_target.');
  250. }
  251. /**
  252. * Rename filepath to uri in {l10n_update_file} table.
  253. */
  254. function l10n_update_update_7001() {
  255. // Only do this update if the field exists from D6.
  256. // If it doesn't, we've got a pure D7 site that doesn't need it.
  257. if (db_field_exists('l10n_update_file', 'filepath')) {
  258. db_change_field('l10n_update_file', 'filepath', 'uri', array(
  259. 'description' => 'File system path for importing the file.',
  260. 'type' => 'varchar',
  261. 'length' => 255,
  262. 'not null' => TRUE,
  263. 'default' => '',
  264. ));
  265. }
  266. }
  267. /**
  268. * Delete 'last_updated' field from {l10n_update_file} table.
  269. */
  270. function l10n_update_update_7002() {
  271. db_drop_field('l10n_update_file', 'last_updated');
  272. }
  273. /**
  274. * Delete 'import_date' field from {l10n_update_file} table.
  275. */
  276. function l10n_update_update_7003() {
  277. db_drop_field('l10n_update_file', 'import_date');
  278. }
  279. /**
  280. * Create {cache_l10n_update} table.
  281. */
  282. function l10n_update_update_7004() {
  283. if (!db_table_exists('cache_l10n_update')) {
  284. $schema = drupal_get_schema_unprocessed('system', 'cache');
  285. $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
  286. db_create_table('cache_l10n_update', $schema);
  287. }
  288. }
  289. /**
  290. * Rebuild registry for 'translations' stream wrapper.
  291. */
  292. function l10n_update_update_7005() {
  293. registry_rebuild();
  294. }
  295. /**
  296. * Rebuild registry after removing the stream wrapper.
  297. */
  298. function l10n_update_update_7006() {
  299. registry_rebuild();
  300. }
  301. /**
  302. * Increase the length of the {l10n_update_project}.name column.
  303. */
  304. function l10n_update_update_7007() {
  305. $schema = l10n_update_schema();
  306. db_change_field('l10n_update_project', 'name', 'name', $schema['l10n_update_project']['fields']['name']);
  307. }
  308. /**
  309. * Increase the length of the {l10n_update_file}.project column.
  310. */
  311. function l10n_update_update_7008() {
  312. $schema = l10n_update_schema();
  313. db_change_field('l10n_update_file', 'project', 'project', $schema['l10n_update_file']['fields']['project']);
  314. }
  315. /**
  316. * Remove 'headers' field from cache table.
  317. */
  318. function l10n_update_update_7009() {
  319. if (db_field_exists('cache_l10n_update', 'headers')) {
  320. db_drop_field('cache_l10n_update', 'headers');
  321. }
  322. }
  323. /**
  324. * Add a .htaccess file to the translations directory.
  325. */
  326. function l10n_update_update_7010() {
  327. module_load_include('module', 'l10n_update');
  328. l10n_update_ensure_htaccess();
  329. }