From e4f0cfe7999cdf6329557494992d6dde44579279 Mon Sep 17 00:00:00 2001 From: florenttorregrosa Date: Thu, 1 Dec 2016 14:42:31 +0100 Subject: [PATCH] Issue #2830562 by Grimreaper, helmo: Update translations on managed sites --- drush/provision_tasks_extra.drush.inc | 23 ++++++++++++++++++ hosting_tasks_extra.module | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/drush/provision_tasks_extra.drush.inc b/drush/provision_tasks_extra.drush.inc index 181e2fa..4f4ff45 100644 --- a/drush/provision_tasks_extra.drush.inc +++ b/drush/provision_tasks_extra.drush.inc @@ -27,6 +27,10 @@ function provision_tasks_extra_drush_command() { 'description' => dt('Runs db updates on a site'), 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, ); + $items['provision-update_translations'] = array( + 'description' => dt('Update translations on a site'), + 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, + ); $items['provision-flush_drush_cache'] = array( 'description' => 'Flushes the Drush cache on the server', 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, @@ -102,6 +106,25 @@ function drush_provision_tasks_extra_provision_update() { } /** + * Implements the provision-update_translations command. + */ +function drush_provision_tasks_extra_provision_update_translations() { + drush_errors_on(); + if (drush_drupal_major_version(d()->root) == 8) { + provision_backend_invoke(d()->name, 'locale-check'); + drush_log(dt('Drush locale-check task completed')); + provision_backend_invoke(d()->name, 'locale-update'); + drush_log(dt('Drush locale-update task completed')); + } + else { + provision_backend_invoke(d()->name, 'l10n-update-refresh'); + drush_log(dt('Drush l10n-update-refresh task completed')); + provision_backend_invoke(d()->name, 'l10n-update'); + drush_log(dt('Drush l10n-update task completed')); + } +} + +/** * Implements drush_hook_COMMAND_pre_validate(). * * Make a backup of the site before we mess with it. diff --git a/hosting_tasks_extra.module b/hosting_tasks_extra.module index 3cbd01d..03b91f4 100644 --- a/hosting_tasks_extra.module +++ b/hosting_tasks_extra.module @@ -24,6 +24,11 @@ function hosting_tasks_extra_hosting_tasks() { 'description' => t('Runs database updates on this site.'), 'dialog' => TRUE, ); + $tasks['site']['update_translations'] = array( + 'title' => t('Update translations'), + 'description' => t('Updates translations on this site.'), + 'dialog' => TRUE, + ); $tasks['site']['features_revert_all'] = array( 'title' => t('Revert features'), 'description' => t('Reverts all features overrides on this site.'), @@ -74,6 +79,15 @@ function hosting_site_update_action($node) { } /** + * Callback for site action. + * + * @see: hosting_task_action_info(). + */ +function hosting_site_update_translations_action($node) { + hosting_add_task($node->nid, 'update_translations'); +} + +/** * Callback for server action. * * @see: hosting_task_action_info(). @@ -109,6 +123,9 @@ function hosting_tasks_extra_permission() { 'title' => t('create update task'), 'description' => t('Run pending database updates on a site.'), ), + 'create update_translations task' => array( + 'title' => t('create update translations task'), + ), 'create flush_drush_cache task' => array( 'title' => t('create flush_drush_cache task'), ), @@ -149,3 +166,30 @@ function hosting_tasks_extra_hosting_task_update_ops() { ), ); } + +/** + * Implements hosting_task_TASK_TYPE_form_validate(). + */ +function hosting_task_update_translations_form_validate($form, &$form_state) { + $site = node_load($form_state['values']['nid']); + + // If the l10n_update module is not enabled, check if it is a Drupal 8 site. + if (!_hosting_tasks_extra_site_has_module($site, 'l10n_update')) { + $platform_node = node_load($site->platform); + $core_major_version = $platform_node->release->version[0]; + if ($core_major_version < 8) { + form_set_error('nid', t('You need to enable the module Localization update on this site and then clear the Drush cache before running this task.')); + } + } +} + +/** + * Helper to determine if a particular site has a module installed. + */ +function _hosting_tasks_extra_site_has_module($node, $module) { + $package = hosting_package_instance_load(array('rid' => $node->nid, 'p.short_name' => $module)); + if (!is_object($package)) { + return FALSE; + } + return $package->status; +} -- 1.9.1