l10n_update.install 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. if (l10n_update_get_projects() && l10n_update_language_list()) {
  176. $requirements['l10n_update']['title'] = t('Translation update status');
  177. if (l10n_update_available_updates()) {
  178. $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
  179. $requirements['l10n_update']['value'] = t('There are available updates');
  180. $requirements['l10n_update']['description'] = t(
  181. '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>.',
  182. array(
  183. '@check_manually' => url('admin/config/regional/translate/update')
  184. )
  185. );
  186. }
  187. else {
  188. $requirements['l10n_update']['severity'] = REQUIREMENT_OK;
  189. $requirements['l10n_update']['value'] = t('All your translations are up to date');
  190. }
  191. }
  192. else {
  193. $requirements['l10n_update']['title'] = t('Translation update status');
  194. $requirements['l10n_update']['value'] = t('No update data available');
  195. $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
  196. //$requirements['update_core']['reason'] = UPDATE_UNKNOWN;
  197. $requirements['l10n_update']['description'] = _l10n_update_no_data();
  198. }
  199. return $requirements;
  200. }
  201. // We must always return array, the installer doesn't use module_invoke_all()
  202. return array();
  203. }
  204. /**
  205. * Add status field to locales_target.
  206. */
  207. function l10n_update_update_6001() {
  208. if (!db_field_exists('locales_target', 'l10n_status')) {
  209. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  210. }
  211. return t('Added l10n_status field to locales_target.');
  212. }
  213. /**
  214. * Change status field name to l10n_status.
  215. */
  216. function l10n_update_update_6002() {
  217. // I18n Strings module adds a 'status' column to 'locales_target' table.
  218. // L10n Update module previously added a column with the same name. To avoid
  219. // any collision we change the column name here, but only if it was added by
  220. // L10n Update module.
  221. if (!db_field_exists('locales_target', 'l10n_status') && db_field_exists('locales_target', 'status') && !db_table_exists('i18n_strings')) {
  222. db_change_field('locales_target', 'status', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  223. }
  224. // Just in case someone did install I18n Strings, we still need to make sure
  225. // the 'l10n_status' column gets created.
  226. elseif (!db_field_exists('locales_target', 'l10n_status')) {
  227. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  228. }
  229. return t('Resolved possible l10n_status field conflict in locales_target.');
  230. }
  231. /**
  232. * Rename filepath to uri in {l10n_update_file} table.
  233. */
  234. function l10n_update_update_7001() {
  235. // Only do this update if the field exists from D6.
  236. // If it doesn't, we've got a pure D7 site that doesn't need it.
  237. if (db_field_exists('l10n_update_file', 'filepath')) {
  238. db_change_field('l10n_update_file', 'filepath', 'uri', array(
  239. 'description' => 'File system path for importing the file.',
  240. 'type' => 'varchar',
  241. 'length' => 255,
  242. 'not null' => TRUE,
  243. 'default' => '',
  244. ));
  245. }
  246. }
  247. /**
  248. * Delete 'last_updated' field from {l10n_update_file} table.
  249. */
  250. function l10n_update_update_7002() {
  251. db_drop_field('l10n_update_file', 'last_updated');
  252. }
  253. /**
  254. * Delete 'import_date' field from {l10n_update_file} table.
  255. */
  256. function l10n_update_update_7003() {
  257. db_drop_field('l10n_update_file', 'import_date');
  258. }
  259. /**
  260. * Create {cache_l10n_update} table.
  261. */
  262. function l10n_update_update_7004() {
  263. if (!db_table_exists('cache_l10n_update')) {
  264. $schema = drupal_get_schema_unprocessed('system', 'cache');
  265. $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
  266. db_create_table('cache_l10n_update', $schema);
  267. }
  268. }