l10n_update.install 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. If TRUE, translations of this module will be updated.',
  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. 'description' => 'Boolean indicating whether the translation is custom to this site.',
  148. );
  149. }
  150. /**
  151. * Implements hook_install().
  152. */
  153. function l10n_update_install() {
  154. db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
  155. variable_set('l10n_update_rebuild_projects', 1);
  156. // Create the translation directory. We try different alternative paths as the
  157. // default may not always be writable.
  158. $directories = array(
  159. variable_get('l10n_update_download_store', L10N_UPDATE_DEFAULT_TRANSLATION_PATH),
  160. variable_get('file_public_path', conf_path() . '/files') . '/translations',
  161. 'sites/default/files/translations',
  162. );
  163. foreach ($directories as $directory) {
  164. if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
  165. variable_set('l10n_update_download_store', $directory);
  166. return;
  167. }
  168. }
  169. watchdog('l10n_update', 'The directory %directory does not exist or is not writable.', array('%directory' => $directories[0]), WATCHDOG_ERROR);
  170. drupal_set_message(t('The directory %directory does not exist or is not writable.', array('%directory' => $directories[0])), 'error');
  171. }
  172. /**
  173. * Implements hook_uninstall().
  174. */
  175. function l10n_update_uninstall() {
  176. db_drop_field('locales_target', 'l10n_status');
  177. variable_del('l10n_update_check_disabled');
  178. variable_del('l10n_update_default_filename');
  179. variable_del('l10n_update_default_update_url');
  180. variable_del('l10n_update_import_enabled');
  181. variable_del('l10n_update_import_mode');
  182. variable_del('l10n_update_check_frequency');
  183. variable_del('l10n_update_last_check');
  184. variable_del('l10n_update_download_store');
  185. variable_del('l10n_update_translation_status');
  186. variable_del('l10n_update_check_mode');}
  187. /**
  188. * Implements hook_requirements().
  189. */
  190. function l10n_update_requirements($phase) {
  191. $requirements = array();
  192. if ($phase == 'runtime') {
  193. $available_updates = array();
  194. $untranslated = array();
  195. $languages = l10n_update_translatable_language_list();
  196. if ($languages) {
  197. // Determine the status of the translation updates per language.
  198. $status = l10n_update_get_status();
  199. if ($status) {
  200. foreach ($status as $project) {
  201. foreach ($project as $langcode => $project_info) {
  202. if (empty($project_info->type)) {
  203. $untranslated[$langcode] = $languages[$langcode];
  204. }
  205. elseif ($project_info->type == L10N_UPDATE_LOCAL || $project_info->type == L10N_UPDATE_REMOTE) {
  206. $available_updates[$langcode] = $languages[$langcode];
  207. }
  208. }
  209. }
  210. if ($available_updates || $untranslated) {
  211. if ($available_updates) {
  212. $requirements['l10n_update'] = array(
  213. 'title' => 'Translation update status',
  214. 'value' => l(t('Updates available'), 'admin/config/regional/translate/update'),
  215. 'severity' => REQUIREMENT_WARNING,
  216. 'description' => t('Updates available for: @languages. See the <a href="!updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $available_updates), '!updates' => url('admin/config/regional/translate/update'))),
  217. );
  218. }
  219. else {
  220. $requirements['l10n_update'] = array(
  221. 'title' => 'Translation update status',
  222. 'value' => t('Missing translations'),
  223. 'severity' => REQUIREMENT_INFO,
  224. 'description' => t('Missing translations for: @languages. See the <a href="!updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $untranslated), '!updates' => url('admin/config/regional/translate/update'))),
  225. );
  226. }
  227. }
  228. else {
  229. $requirements['l10n_update'] = array(
  230. 'title' => 'Translation update status',
  231. 'value' => t('Up to date'),
  232. 'severity' => REQUIREMENT_OK,
  233. );
  234. }
  235. }
  236. else {
  237. $requirements['locale_translation'] = array(
  238. 'title' => 'Translation update status',
  239. 'value' => l(t('Can not determine status'), 'admin/config/regional/translate/update'),
  240. 'severity' => REQUIREMENT_WARNING,
  241. 'description' => t('No translation status is available. See the <a href="!updates">Available translation updates</a> page for more information.', array('!updates' => url('admin/config/regional/translate/update'))),
  242. );
  243. }
  244. }
  245. }
  246. if ($phase == 'update') {
  247. // Make sure the 'translations' stream wrapper class gets registered.
  248. // This is needed when upgrading to 7.x-2.x.
  249. if (!class_exists('TranslationsStreamWrapper')) {
  250. registry_rebuild();
  251. }
  252. }
  253. return $requirements;
  254. }
  255. /**
  256. * Rename filepath to uri in {l10n_update_file} table.
  257. */
  258. function l10n_update_update_7001() {
  259. // Only do this update if the field exists from D6.
  260. // If it doesn't, we've got a pure D7 site that doesn't need it.
  261. if (db_field_exists('l10n_update_file', 'filepath')) {
  262. db_change_field('l10n_update_file', 'filepath', 'uri', array(
  263. 'description' => 'File system path for importing the file.',
  264. 'type' => 'varchar',
  265. 'length' => 255,
  266. 'not null' => TRUE,
  267. 'default' => '',
  268. ));
  269. }
  270. }
  271. /**
  272. * Delete 'last_updated' field from {l10n_update_file} table.
  273. */
  274. function l10n_update_update_7002() {
  275. db_drop_field('l10n_update_file', 'last_updated');
  276. }
  277. /**
  278. * Delete 'import_date' field from {l10n_update_file} table.
  279. */
  280. function l10n_update_update_7003() {
  281. db_drop_field('l10n_update_file', 'import_date');
  282. }
  283. /**
  284. * Create {cache_l10n_update} table.
  285. */
  286. function l10n_update_update_7004() {
  287. if (!db_table_exists('cache_l10n_update')) {
  288. $schema = drupal_get_schema_unprocessed('system', 'cache');
  289. $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
  290. db_create_table('cache_l10n_update', $schema);
  291. }
  292. }
  293. /**
  294. * Migration to 7.x-2.x branch.
  295. */
  296. function l10n_update_update_7200() {
  297. // Make sure the 'translations' stream wrapper class gets registered.
  298. if (!class_exists('TranslationsStreamWrapper')) {
  299. registry_rebuild();
  300. }
  301. if (!variable_get('l10n_update_download_store', '')) {
  302. variable_set('l10n_update_download_store', 'sites/all/translations');
  303. }
  304. // Create the translation directory. We try different alternative paths as the
  305. // default may not always be writable.
  306. $directories = array(
  307. variable_get('l10n_update_download_store', L10N_UPDATE_DEFAULT_TRANSLATION_PATH),
  308. variable_get('file_public_path', conf_path() . '/files') . '/translations',
  309. 'sites/default/files/translations',
  310. );
  311. foreach ($directories as $directory) {
  312. if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
  313. variable_set('l10n_update_download_store', $directory);
  314. return;
  315. }
  316. }
  317. watchdog('l10n_update', 'The directory %directory does not exist or is not writable.', array('%directory' => $directories[0]), WATCHDOG_ERROR);
  318. drupal_set_message(t('The directory %directory does not exist or is not writable.', array('%directory' => $directories[0])), 'error');
  319. // Translation source 'Remote server only' is no longer supported. Use 'Remote
  320. // and local' instead.
  321. $mode = variable_get('l10n_update_check_mode', 3); // L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL
  322. if ($mode == 1) {
  323. variable_set('l10n_update_check_mode', 3); // L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL
  324. }
  325. // Daily cron updates are no longer supported. Use weekly instead.
  326. $frequency = variable_get('l10n_update_check_frequency', '0');
  327. if ($frequency == '1') {
  328. variable_set('l10n_update_check_frequency', '7');
  329. }
  330. // Clean up deprecated variables.
  331. variable_del('l10n_update_default_server');
  332. variable_del('l10n_update_default_server_url');
  333. variable_del('l10n_update_rebuild_projects');
  334. }
  335. /**
  336. * Sets the default translation files directory.
  337. */
  338. function l10n_update_update_7201() {
  339. if (!variable_get('l10n_update_download_store', '')) {
  340. variable_set('l10n_update_download_store', 'sites/all/translations');
  341. }
  342. }