Esempio n. 1
1
 /**
  * Starts the batch process depending on where it was requested from.
  */
 public function start()
 {
     switch ($this->batchInfo['from']) {
         case 'form':
             batch_set($this->batch);
             break;
         case 'drush':
             batch_set($this->batch);
             $this->batch =& batch_get();
             $this->batch['progressive'] = FALSE;
             drush_log(t(self::BATCH_INIT_MESSAGE), 'status');
             drush_backend_batch_process();
             break;
         case 'backend':
             batch_set($this->batch);
             $this->batch =& batch_get();
             $this->batch['progressive'] = FALSE;
             batch_process();
             //todo: Does not take advantage of batch API and eventually runs out of memory on very large sites.
             break;
         case 'nobatch':
             $context = [];
             foreach ($this->batch['operations'] as $i => $operation) {
                 $operation[1][] =& $context;
                 call_user_func_array($operation[0], $operation[1]);
             }
             self::finishGeneration(TRUE, $context['results'], []);
             break;
     }
 }
Esempio n. 2
0
 /**
  * Manually checks the update status without the use of cron.
  */
 public function updateStatusManually()
 {
     $this->updateManager->refreshUpdateData();
     $batch = array('operations' => array(array(array($this->updateManager, 'fetchDataBatch'), array())), 'finished' => 'update_fetch_data_finished', 'title' => t('Checking available update data'), 'progress_message' => t('Trying to check available update data ...'), 'error_message' => t('Error checking available update data.'));
     batch_set($batch);
     return batch_process('admin/reports/updates');
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function doSubmitForm(&$form, FormStateInterface &$form_state)
 {
     if (!$form_state->isSubmitted()) {
         return;
     }
     // Execute form submit handlers.
     $this->executeSubmitHandlers($form, $form_state);
     // If batches were set in the submit handlers, we process them now,
     // possibly ending execution. We make sure we do not react to the batch
     // that is already being processed (if a batch operation performs a
     // \Drupal\Core\Form\FormBuilderInterface::submitForm).
     if (($batch =& $this->batchGet()) && !isset($batch['current_set'])) {
         // Store $form_state information in the batch definition.
         $batch['form_state'] = $form_state;
         $batch['progressive'] = !$form_state->isProgrammed();
         $response = batch_process();
         if ($batch['progressive']) {
             return $response;
         }
         // Execution continues only for programmatic forms.
         // For 'regular' forms, we get redirected to the batch processing
         // page. Form redirection will be handled in _batch_finished(),
         // after the batch is processed.
     }
     // Set a flag to indicate the form has been processed and executed.
     $form_state->setExecuted();
     // If no response has been set, process the form redirect.
     if (!$form_state->getResponse() && ($redirect = $this->redirectForm($form_state))) {
         $form_state->setResponse($redirect);
     }
     // If there is a response was set, return it instead of continuing.
     if (($response = $form_state->getResponse()) && $response instanceof Response) {
         return $response;
     }
 }
 public function get_movies()
 {
     $batch = array('title' => t('Importing Douban Movies'), 'operations' => array(array('doubanmovie_get_movies', array())), 'finished' => 'my_finished_callback', 'file' => drupal_get_path('module', 'doubanmovie') . '/doubanmovie.batch.inc');
     batch_set($batch);
     // Only needed if not inside a form _submit handler.
     // Setting redirect in batch_process.
     return batch_process('node/1');
 }
Esempio n. 5
0
 /**
  * Block a user and remove or reassign their content.
  */
 public function cancel()
 {
     if (drush_get_option('delete-content')) {
         user_cancel(array(), $this->id(), 'user_cancel_delete');
     } else {
         user_cancel(array(), $this->id(), 'user_cancel_reassign');
     }
     // I got the following technique here: http://drupal.org/node/638712
     $batch =& batch_get();
     $batch['progressive'] = FALSE;
     batch_process();
 }
Esempio n. 6
0
 /**
  * Checks for translation updates and displays the translations status.
  *
  * Manually checks the translation status without the use of cron.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirection to translations reports page.
  */
 public function checkTranslation()
 {
     $this->moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
     // Check translation status of all translatable project in all languages.
     // First we clear the cached list of projects. Although not strictly
     // necessary, this is helpful in case the project list is out of sync.
     locale_translation_flush_projects();
     locale_translation_check_projects();
     // Execute a batch if required. A batch is only used when remote files
     // are checked.
     if (batch_get()) {
         return batch_process('admin/reports/translations');
     }
     return $this->redirect('locale.translate_status');
 }
 /**
  * Checks for translation updates and displays the translations status.
  *
  * Manually checks the translation status without the use of cron.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirection to translations reports page.
  */
 public function checkTranslation()
 {
     $this->moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');
     // Check translation status of all translatable project in all languages.
     // First we clear the cached list of projects. Although not strictly
     // necessary, this is helpful in case the project list is out of sync.
     locale_translation_flush_projects();
     locale_translation_check_projects();
     // Execute a batch if required. A batch is only used when remote files
     // are checked.
     if (batch_get()) {
         return batch_process('admin/reports/translations');
     }
     // @todo Use $this->redirect() after https://drupal.org/node/1978926.
     return new RedirectResponse($this->getUrlGenerator()->generateFromPath('admin/reports/translations', array('absolute' => TRUE)));
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function doSubmitForm(&$form, &$form_state)
 {
     if (!$form_state['submitted']) {
         return;
     }
     // Execute form submit handlers.
     $this->executeSubmitHandlers($form, $form_state);
     // If batches were set in the submit handlers, we process them now,
     // possibly ending execution. We make sure we do not react to the batch
     // that is already being processed (if a batch operation performs a
     // \Drupal\Core\Form\FormBuilderInterface::submitForm).
     if (($batch =& $this->batchGet()) && !isset($batch['current_set'])) {
         // Store $form_state information in the batch definition.
         // We need the full $form_state when either:
         // - Some submit handlers were saved to be called during batch
         //   processing. See self::executeSubmitHandlers().
         // - The form is multistep.
         // In other cases, we only need the information expected by
         // self::redirectForm().
         if ($batch['has_form_submits'] || !empty($form_state['rebuild'])) {
             $batch['form_state'] = $form_state;
         } else {
             $batch['form_state'] = array_intersect_key($form_state, array_flip(array('programmed', 'rebuild', 'storage', 'no_redirect', 'redirect', 'redirect_route')));
         }
         $batch['progressive'] = !$form_state['programmed'];
         $response = batch_process();
         if ($batch['progressive']) {
             return $response;
         }
         // Execution continues only for programmatic forms.
         // For 'regular' forms, we get redirected to the batch processing
         // page. Form redirection will be handled in _batch_finished(),
         // after the batch is processed.
     }
     // Set a flag to indicate the the form has been processed and executed.
     $form_state['executed'] = TRUE;
     // If no response has been set, process the form redirect.
     if (!isset($form_state['response']) && ($redirect = $this->redirectForm($form_state))) {
         $form_state['response'] = $redirect;
     }
     // If there is a response was set, return it instead of continuing.
     if (isset($form_state['response']) && $form_state['response'] instanceof Response) {
         return $form_state['response'];
     }
 }
Esempio n. 9
0
function action_begin()
{
    $transaction = TransactionSession::getFromSession();
    if (!$transaction) {
        drupal_access_denied();
    }
    // If there are no root entities, throw an error.
    $root_entities = $transaction->getRootEntities();
    if (count($root_entities) <= 0) {
        drupal_access_denied();
    }
    // Launch a batch session to get all the dependencies of the root entities.
    $queue = new \Drupal\publisher\Batch\BeginOperationQueue();
    foreach ($root_entities as $root_entity) {
        $queue->addOperation(new \Drupal\publisher\Batch\BeginOperation(), $root_entity['entity'], $transaction->getRemote(), $root_entity['options']);
    }
    $queue->start();
    // We'll need to call batch_process because we're not in the context of a
    // form's submit handler.
    batch_process('publisher/feedback');
}
Esempio n. 10
0
 /**
  * Runs batch process of user accounts synchronization on submit form above
  * 
  * @param array &$form      Form descriptions
  * @param array &$formState Form state
  *  
  * @return void
  */
 public function processUserSyncFormSubmit(array &$form, array &$formState)
 {
     if (t(self::LC_OP_NAME_USERSYNC) == $formState['values']['op']) {
         if ($this->isUserSynchronizationRequired()) {
             variable_set('lc_user_sync_notify', $formState['values']['notify_users']);
             // Calculate number of steps and list ot operations
             $maxSteps = $this->totalNonSynchronizedAccounts;
             // $this->userAccountsPerStepCounter) + 1;
             $operations = array();
             for ($i = 0; $i < $maxSteps; $i++) {
                 $operations[] = array('lcConnectorUserSync', array());
             }
             // Initialize batch (to set title).
             $batch = array('title' => t('Synchronize user accounts'), 'init_message' => t('Starting user accounts synchronization...'), 'operations' => $operations, 'finished' => 'lcConnectorUserSyncFinishedCallback');
             batch_set($batch);
             // Run batch process
             batch_process();
         } else {
             drupal_set_message(t('User accounts synchronization is not required.'));
         }
     }
 }
Esempio n. 11
0
function update_batch()
{
    global $base_url;
    // During the update, bring the site offline so that schema changes do not
    // affect visiting users.
    $_SESSION['site_offline'] = variable_get('site_offline', FALSE);
    if ($_SESSION['site_offline'] == FALSE) {
        variable_set('site_offline', TRUE);
    }
    $operations = array();
    // Set the installed version so updates start at the correct place.
    foreach ($_POST['start'] as $module => $version) {
        drupal_set_installed_schema_version($module, $version - 1);
        $updates = drupal_get_schema_versions($module);
        $max_version = max($updates);
        if ($version <= $max_version) {
            foreach ($updates as $update) {
                if ($update >= $version) {
                    $operations[] = array('update_do_one', array($module, $update));
                }
            }
        }
    }
    $batch = array('operations' => $operations, 'title' => 'Updating', 'init_message' => 'Starting updates', 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.', 'finished' => 'update_finished');
    batch_set($batch);
    batch_process($base_url . '/update.php?op=results', $base_url . '/update.php');
}
Esempio n. 12
0
 public function processBatch()
 {
     $batch =& batch_get();
     $batch['progressive'] = FALSE;
     batch_process();
 }
Esempio n. 13
0
/**
 * Run an individual installation task.
 *
 * @param $task
 *   An array of information about the task to be run.
 * @param $install_state
 *   An array of information about the current installation state. This is
 *   passed in by reference so that it can be modified by the task.
 * @return
 *   The output of the task function, if there is any.
 */
function install_run_task($task, &$install_state)
{
    $function = $task['function'];
    if ($task['type'] == 'form') {
        require_once DRUPAL_ROOT . '/includes/form.inc';
        if ($install_state['interactive']) {
            // For interactive forms, build the form and ensure that it will not
            // redirect, since the installer handles its own redirection only after
            // marking the form submission task complete.
            $form_state = array('args' => array(&$install_state), 'no_redirect' => TRUE);
            $form = drupal_build_form($function, $form_state);
            // If a successful form submission did not occur, the form needs to be
            // rendered, which means the task is not complete yet.
            if (empty($form_state['executed'])) {
                $install_state['task_not_complete'] = TRUE;
                return drupal_render($form);
            }
            // Otherwise, return nothing so the next task will run in the same
            // request.
            return;
        } else {
            // For non-interactive forms, submit the form programmatically with the
            // values taken from the installation state. Throw an exception if any
            // errors were encountered.
            $form_state = array('values' => !empty($install_state['forms'][$function]) ? $install_state['forms'][$function] : array());
            drupal_form_submit($function, $form_state, $install_state);
            $errors = form_get_errors();
            if (!empty($errors)) {
                throw new Exception(implode("\n", $errors));
            }
        }
    } elseif ($task['type'] == 'batch') {
        // Start a new batch based on the task function, if one is not running
        // already.
        $current_batch = variable_get('install_current_batch');
        if (!$install_state['interactive'] || !$current_batch) {
            $batch = $function($install_state);
            if (empty($batch)) {
                // If the task did some processing and decided no batch was necessary,
                // there is nothing more to do here.
                return;
            }
            batch_set($batch);
            // For interactive batches, we need to store the fact that this batch
            // task is currently running. Otherwise, we need to make sure the batch
            // will complete in one page request.
            if ($install_state['interactive']) {
                variable_set('install_current_batch', $function);
            } else {
                $batch =& batch_get();
                $batch['progressive'] = FALSE;
            }
            // Process the batch. For progressive batches, this will redirect.
            // Otherwise, the batch will complete.
            batch_process(install_redirect_url($install_state), install_full_redirect_url($install_state));
        } elseif ($current_batch == $function) {
            include_once DRUPAL_ROOT . '/includes/batch.inc';
            $output = _batch_page();
            // The task is complete when we try to access the batch page and receive
            // FALSE in return, since this means we are at a URL where we are no
            // longer requesting a batch ID.
            if ($output === FALSE) {
                // Return nothing so the next task will run in the same request.
                variable_del('install_current_batch');
                return;
            } else {
                // We need to force the page request to end if the task is not
                // complete, since the batch API sometimes prints JSON output
                // rather than returning a themed page.
                $install_state['task_not_complete'] = $install_state['stop_page_request'] = TRUE;
                return $output;
            }
        }
    } else {
        // For normal tasks, just return the function result, whatever it is.
        return $function($install_state);
    }
}
Esempio n. 14
0
/**
 * Tasks performed after the database is initialized.
 */
function install_tasks($profile, $task)
{
    global $base_url, $install_locale;
    // Bootstrap newly installed Drupal, while preserving existing messages.
    $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : '';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
    $_SESSION['messages'] = $messages;
    // URL used to direct page requests.
    $url = $base_url . '/install.php?locale=' . $install_locale . '&profile=' . $profile;
    // Build a page for final tasks.
    if (empty($task)) {
        variable_set('install_task', 'profile-install');
        $task = 'profile-install';
    }
    // We are using a list of if constructs here to allow for
    // passing from one task to the other in the same request.
    // Install profile modules.
    if ($task == 'profile-install') {
        $modules = variable_get('install_profile_modules', array());
        $files = module_rebuild_cache();
        variable_del('install_profile_modules');
        $operations = array();
        foreach ($modules as $module) {
            $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
        }
        $batch = array('operations' => $operations, 'finished' => '_install_profile_batch_finished', 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_name())), 'error_message' => st('The installation has encountered an error.'));
        // Start a batch, switch to 'profile-install-batch' task. We need to
        // set the variable here, because batch_process() redirects.
        variable_set('install_task', 'profile-install-batch');
        batch_set($batch);
        batch_process($url, $url);
    }
    // We are running a batch install of the profile's modules.
    // This might run in multiple HTTP requests, constantly redirecting
    // to the same address, until the batch finished callback is invoked
    // and the task advances to 'locale-initial-import'.
    if ($task == 'profile-install-batch') {
        include_once 'includes/batch.inc';
        $output = _batch_page();
    }
    // Import interface translations for the enabled modules.
    if ($task == 'locale-initial-import') {
        if (!empty($install_locale) && $install_locale != 'en') {
            include_once 'includes/locale.inc';
            // Enable installation language as default site language.
            locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE);
            // Collect files to import for this language.
            $batch = locale_batch_by_language($install_locale, '_install_locale_initial_batch_finished');
            if (!empty($batch)) {
                // Remember components we cover in this batch set.
                variable_set('install_locale_batch_components', $batch['#components']);
                // Start a batch, switch to 'locale-batch' task. We need to
                // set the variable here, because batch_process() redirects.
                variable_set('install_task', 'locale-initial-batch');
                batch_set($batch);
                batch_process($url, $url);
            }
        }
        // Found nothing to import or not foreign language, go to next task.
        $task = 'configure';
    }
    if ($task == 'locale-initial-batch') {
        include_once 'includes/batch.inc';
        include_once 'includes/locale.inc';
        $output = _batch_page();
    }
    if ($task == 'configure') {
        if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) {
            // Site already configured: This should never happen, means re-running
            // the installer, possibly by an attacker after the 'install_task' variable
            // got accidentally blown somewhere. Stop it now.
            install_already_done_error();
        }
        $form = drupal_get_form('install_configure_form', $url);
        if (!variable_get('site_name', FALSE) && !variable_get('site_mail', FALSE)) {
            // Not submitted yet: Prepare to display the form.
            $output = $form;
            drupal_set_title(st('Configure site'));
            // Warn about settings.php permissions risk
            $settings_dir = './' . conf_path();
            $settings_file = $settings_dir . '/settings.php';
            if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) {
                drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, please consult the <a href="@handbook_url">on-line handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/getting-started')), 'error');
            } else {
                drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file)));
            }
            // Add JavaScript validation.
            _user_password_dynamic_validation();
            drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module');
            // We add these strings as settings because JavaScript translation does not
            // work on install time.
            drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')), 'cleanURL' => array('success' => st('Your server has been successfully tested to support this feature.'), 'failure' => st('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.'), 'testing' => st('Testing clean URLs...'))), 'setting');
            drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    Drupal.cleanURLsInstallCheck();
    Drupal.setDefaultTimezone();
  });
}', 'inline');
            // Build menu to allow clean URL check.
            menu_rebuild();
        } else {
            $task = 'profile';
        }
    }
    // If found an unknown task or the 'profile' task, which is
    // reserved for profiles, hand over the control to the profile,
    // so it can run any number of custom tasks it defines.
    if (!in_array($task, install_reserved_tasks())) {
        $function = $profile . '_profile_tasks';
        if (function_exists($function)) {
            // The profile needs to run more code, maybe even more tasks.
            // $task is sent through as a reference and may be changed!
            $output = $function($task, $url);
        }
        // If the profile doesn't move on to a new task we assume
        // that it is done.
        if ($task == 'profile') {
            $task = 'profile-finished';
        }
    }
    // Profile custom tasks are done, so let the installer regain
    // control and proceed with importing the remaining translations.
    if ($task == 'profile-finished') {
        if (!empty($install_locale) && $install_locale != 'en') {
            include_once 'includes/locale.inc';
            // Collect files to import for this language. Skip components
            // already covered in the initial batch set.
            $batch = locale_batch_by_language($install_locale, '_install_locale_remaining_batch_finished', variable_get('install_locale_batch_components', array()));
            // Remove temporary variable.
            variable_del('install_locale_batch_components');
            if (!empty($batch)) {
                // Start a batch, switch to 'locale-remaining-batch' task. We need to
                // set the variable here, because batch_process() redirects.
                variable_set('install_task', 'locale-remaining-batch');
                batch_set($batch);
                batch_process($url, $url);
            }
        }
        // Found nothing to import or not foreign language, go to next task.
        $task = 'finished';
    }
    if ($task == 'locale-remaining-batch') {
        include_once 'includes/batch.inc';
        include_once 'includes/locale.inc';
        $output = _batch_page();
    }
    // Display a 'finished' page to user.
    if ($task == 'finished') {
        drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
        $messages = drupal_set_message();
        $output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>';
        $output .= '<p>' . (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>';
        $task = 'done';
    }
    // The end of the install process. Remember profile used.
    if ($task == 'done') {
        // Rebuild menu to get content type links registered by the profile,
        // and possibly any other menu items created through the tasks.
        menu_rebuild();
        // Register actions declared by any modules.
        actions_synchronize();
        // Randomize query-strings on css/js files, to hide the fact that
        // this is a new install, not upgraded yet.
        _drupal_flush_css_js();
        variable_set('install_profile', $profile);
    }
    // Set task for user, and remember the task in the database.
    install_task_list($task);
    variable_set('install_task', $task);
    // Output page, if some output was required. Otherwise it is possible
    // that we are printing a JSON page and theme output should not be there.
    if (isset($output)) {
        print theme('maintenance_page', $output);
    }
}
 /**
  * Confirms cancelling a user account via an email link.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user account.
  * @param int $timestamp
  *   The timestamp.
  * @param string $hashed_pass
  *   The hashed password.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect response.
  */
 public function confirmCancel(UserInterface $user, $timestamp = 0, $hashed_pass = '')
 {
     // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
     $timeout = 86400;
     $current = REQUEST_TIME;
     // Basic validation of arguments.
     $account_data = $this->userData->get('user', $user->id());
     if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
         // Validate expiration and hashed password/login.
         if ($timestamp <= $current && $current - $timestamp < $timeout && $user->id() && $timestamp >= $user->getLastLoginTime() && Crypt::hashEquals($hashed_pass, user_pass_rehash($user, $timestamp))) {
             $edit = array('user_cancel_notify' => isset($account_data['cancel_notify']) ? $account_data['cancel_notify'] : $this->config('user.settings')->get('notify.status_canceled'));
             user_cancel($edit, $user->id(), $account_data['cancel_method']);
             // Since user_cancel() is not invoked via Form API, batch processing
             // needs to be invoked manually and should redirect to the front page
             // after completion.
             return batch_process('');
         } else {
             drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'error');
             return $this->redirect('entity.user.cancel_form', ['user' => $user->id()], ['absolute' => TRUE]);
         }
     }
     throw new AccessDeniedHttpException();
 }
 /**
  * Overrides SearchApiEntityDataSourceController::startTracking().
  *
  * Reverts the behavior to always use getAllItemIds(), instead of taking a
  * shortcut via "base table".
  *
  * This method will also be called when the multilingual configuration of an
  * index changes, to take care of new and/or out-dated IDs.
  */
 public function startTracking(array $indexes)
 {
     if (!$this->table) {
         return;
     }
     // We first clear the tracking table for all indexes, so we can just insert
     // all items again without any key conflicts.
     $this->stopTracking($indexes);
     $operations = array();
     // Find out number of all entities to be processed.
     foreach ($indexes as $index) {
         $entity_ids = $this->getTrackableEntityIds($index);
         $steps = ceil(count($entity_ids) / $index->options['cron_limit']);
         for ($step = 0; $step < $steps; $step++) {
             $operations[] = array('search_api_et_batch_queue_entities', array($index, $entity_ids, $step));
         }
     }
     // This might be called both from web interface as well as from drush.
     $t = drupal_is_cli() ? 'dt' : 't';
     $batch = array('title' => $t('Adding items to the index queue'), 'operations' => $operations, 'finished' => 'search_api_et_batch_queue_entities_finished', 'progress_message' => $t('Completed about @percentage% of the queueing operation.'), 'file' => drupal_get_path('module', 'search_api_et') . '/search_api_et.batch.inc');
     batch_set($batch);
     if (drupal_is_cli()) {
         // Calling drush_backend_batch_process() to start batch execution directly
         // from here doesn't work for some unknown reason, so we need to call it
         // from a shutdown function instead.
         drupal_register_shutdown_function('search_api_et_shutdown_batch_process');
     } else {
         batch_process();
     }
 }
Esempio n. 17
0
 /**
  * Starts the database update batch process.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  */
 protected function triggerBatch(Request $request)
 {
     // During the update, bring the site offline so that schema changes do not
     // affect visiting users.
     $maintenance_mode = $this->config('system.maintenance')->get('enabled');
     if (isset($maintenance_mode)) {
         $_SESSION['maintenance_mode'] = $maintenance_mode;
     }
     if (empty($_SESSION['maintenance_mode'])) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     $operations = array();
     // First of all perform entity definition updates, which will update
     // storage schema if needed, so that module update functions work with
     // the correct entity schema.
     if ($this->entityDefinitionUpdateManager->needsUpdates()) {
         $operations[] = array('update_entity_definitions', array('system', '0 - Update entity definitions'));
     }
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     $start = $this->getModuleUpdates();
     $updates = update_resolve_dependencies($start);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependency_map = array();
     foreach ($updates as $function => $update) {
         $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     // Determine updates to be performed.
     foreach ($updates as $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($start[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($start[$update['module']]);
             }
             // Add this update function to the batch.
             $function = $update['module'] . '_update_' . $update['number'];
             $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
         }
     }
     $batch['operations'] = $operations;
     $batch += array('title' => $this->t('Updating'), 'init_message' => $this->t('Starting updates'), 'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'), 'finished' => array('\\Drupal\\system\\Controller\\DbUpdateController', 'batchFinished'));
     batch_set($batch);
     return batch_process('update.php/results', Url::fromRoute('system.db_update', array('op' => 'start')));
 }
 /**
  * Runs a batch for testing theme used on the progress page.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  *   A redirect response if the batch is progressive. No return value otherwise.
  */
 public function testThemeBatch()
 {
     batch_test_stack(NULL, TRUE);
     $batch = array('operations' => array(array('_batch_test_theme_callback', array())));
     batch_set($batch);
     return batch_process('batch-test/redirect');
 }
Esempio n. 19
0
 /**
  * Starts the database update batch process.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  */
 protected function triggerBatch(Request $request)
 {
     $maintenance_mode = $this->state->get('system.maintenance_mode', FALSE);
     // Store the current maintenance mode status in the session so that it can
     // be restored at the end of the batch.
     $_SESSION['maintenance_mode'] = $maintenance_mode;
     // During the update, always put the site into maintenance mode so that
     // in-progress schema changes do not affect visiting users.
     if (empty($maintenance_mode)) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     $operations = array();
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     $start = $this->getModuleUpdates();
     $updates = update_resolve_dependencies($start);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependency_map = array();
     foreach ($updates as $function => $update) {
         $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     // Determine updates to be performed.
     foreach ($updates as $function => $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($start[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($start[$update['module']]);
             }
             $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
         }
     }
     $post_updates = $this->postUpdateRegistry->getPendingUpdateFunctions();
     if ($post_updates) {
         // Now we rebuild all caches and after that execute the hook_post_update()
         // functions.
         $operations[] = ['drupal_flush_all_caches', []];
         foreach ($post_updates as $function) {
             $operations[] = ['update_invoke_post_update', [$function]];
         }
     }
     $batch['operations'] = $operations;
     $batch += array('title' => $this->t('Updating'), 'init_message' => $this->t('Starting updates'), 'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'), 'finished' => array('\\Drupal\\system\\Controller\\DbUpdateController', 'batchFinished'));
     batch_set($batch);
     // @todo Revisit once https://www.drupal.org/node/2548095 is in.
     return batch_process(Url::fromUri('base://results'), Url::fromUri('base://start'));
 }
Esempio n. 20
0
 /**
  * Runs a batch for testing the title shown on the progress page.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  *   A redirect response if the batch is progressive. No return value otherwise.
  */
 public function testTitleBatch()
 {
     batch_test_stack(NULL, TRUE);
     $batch = ['title' => 'Batch Test', 'operations' => [['_batch_test_title_callback', []]]];
     batch_set($batch);
     return batch_process('batch-test/redirect');
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function processBatch()
 {
     $this->validateDrupalSite();
     $batch =& batch_get();
     $batch['progressive'] = FALSE;
     batch_process();
 }
Esempio n. 22
0
 /**
  * Starts the database update batch process.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  */
 protected function triggerBatch(Request $request)
 {
     $maintenance_mode = $this->state->get('system.maintenance_mode', FALSE);
     // Store the current maintenance mode status in the session so that it can
     // be restored at the end of the batch.
     $_SESSION['maintenance_mode'] = $maintenance_mode;
     // During the update, always put the site into maintenance mode so that
     // in-progress schema changes do not affect visiting users.
     if (empty($maintenance_mode)) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     $operations = array();
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     $start = $this->getModuleUpdates();
     $updates = update_resolve_dependencies($start);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependency_map = array();
     foreach ($updates as $function => $update) {
         $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     // Determine updates to be performed.
     foreach ($updates as $function => $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($start[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($start[$update['module']]);
             }
             $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
         }
     }
     // Lastly, perform entity definition updates, which will update storage
     // schema if needed. If module update functions need to work with specific
     // entity schema they should call the entity update service for the specific
     // update themselves.
     // @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::applyEntityUpdate()
     // @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::applyFieldUpdate()
     if ($this->entityDefinitionUpdateManager->needsUpdates()) {
         $operations[] = array('update_entity_definitions', array());
     }
     $batch['operations'] = $operations;
     $batch += array('title' => $this->t('Updating'), 'init_message' => $this->t('Starting updates'), 'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'), 'finished' => array('\\Drupal\\system\\Controller\\DbUpdateController', 'batchFinished'));
     batch_set($batch);
     return batch_process(Url::fromUri($request->getUriForPath('/results')), Url::fromUri($request->getUriForPath('/start')));
 }