l10n_update.install 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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' => '50',
  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' => '50',
  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. return $requirements;
  201. }
  202. // We must always return array, the installer doesn't use module_invoke_all()
  203. return array();
  204. }
  205. /**
  206. * Add status field to locales_target.
  207. */
  208. function l10n_update_update_6001() {
  209. if (!db_field_exists('locales_target', 'l10n_status')) {
  210. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  211. }
  212. return t('Added l10n_status field to locales_target.');
  213. }
  214. /**
  215. * Change status field name to l10n_status.
  216. */
  217. function l10n_update_update_6002() {
  218. // I18n Strings module adds a 'status' column to 'locales_target' table.
  219. // L10n Update module previously added a column with the same name. To avoid
  220. // any collision we change the column name here, but only if it was added by
  221. // L10n Update module.
  222. if (!db_field_exists('locales_target', 'l10n_status') && db_field_exists('locales_target', 'status') && !db_table_exists('i18n_strings')) {
  223. db_change_field('locales_target', 'status', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  224. }
  225. // Just in case someone did install I18n Strings, we still need to make sure
  226. // the 'l10n_status' column gets created.
  227. elseif (!db_field_exists('locales_target', 'l10n_status')) {
  228. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  229. }
  230. return t('Resolved possible l10n_status field conflict in locales_target.');
  231. }
  232. /**
  233. * Rename filepath to uri in {l10n_update_file} table.
  234. */
  235. function l10n_update_update_7001() {
  236. // Only do this update if the field exists from D6.
  237. // If it doesn't, we've got a pure D7 site that doesn't need it.
  238. if (db_field_exists('l10n_update_file', 'filepath')) {
  239. db_change_field('l10n_update_file', 'filepath', 'uri', array(
  240. 'description' => 'File system path for importing the file.',
  241. 'type' => 'varchar',
  242. 'length' => 255,
  243. 'not null' => TRUE,
  244. 'default' => '',
  245. ));
  246. }
  247. }
  248. /**
  249. * Delete 'last_updated' field from {l10n_update_file} table.
  250. */
  251. function l10n_update_update_7002() {
  252. db_drop_field('l10n_update_file', 'last_updated');
  253. }
  254. /**
  255. * Delete 'import_date' field from {l10n_update_file} table.
  256. */
  257. function l10n_update_update_7003() {
  258. db_drop_field('l10n_update_file', 'import_date');
  259. }
  260. /**
  261. * Create {cache_l10n_update} table.
  262. */
  263. function l10n_update_update_7004() {
  264. if (!db_table_exists('cache_l10n_update')) {
  265. $schema = drupal_get_schema_unprocessed('system', 'cache');
  266. $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
  267. db_create_table('cache_l10n_update', $schema);
  268. }
  269. }
  270. /**
  271. * Rebuild registry for 'translations' stream wrapper.
  272. */
  273. function l10n_update_update_7005() {
  274. registry_rebuild();
  275. }
  276. /**
  277. * Rebuild registry after removing the stream wrapper.
  278. */
  279. function l10n_update_update_7006() {
  280. registry_rebuild();
  281. }