Chris@0: root = $root; Chris@0: $this->moduleHandler = $module_handler; Chris@0: $this->state = $state; Chris@0: $this->sitePath = $site_path; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getFormId() { Chris@0: return 'update_manager_update_ready_form'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container) { Chris@0: return new static( Chris@0: $container->get('update.root'), Chris@0: $container->get('module_handler'), Chris@0: $container->get('state'), Chris@0: $container->get('site.path') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildForm(array $form, FormStateInterface $form_state) { Chris@0: $this->moduleHandler->loadInclude('update', 'inc', 'update.manager'); Chris@0: if (!_update_manager_check_backends($form, 'update')) { Chris@0: return $form; Chris@0: } Chris@0: Chris@0: $form['backup'] = [ Chris@0: '#prefix' => '', Chris@0: '#markup' => $this->t('Back up your database and site before you continue. Learn how.', [':backup_url' => 'https://www.drupal.org/node/22281']), Chris@0: '#suffix' => '', Chris@0: ]; Chris@0: Chris@0: $form['maintenance_mode'] = [ Chris@0: '#title' => $this->t('Perform updates with site in maintenance mode (strongly recommended)'), Chris@0: '#type' => 'checkbox', Chris@0: '#default_value' => TRUE, Chris@0: ]; Chris@0: Chris@0: $form['actions'] = ['#type' => 'actions']; Chris@0: $form['actions']['submit'] = [ Chris@0: '#type' => 'submit', Chris@0: '#value' => $this->t('Continue'), Chris@0: ]; Chris@0: Chris@0: return $form; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function submitForm(array &$form, FormStateInterface $form_state) { Chris@0: // Store maintenance_mode setting so we can restore it when done. Chris@0: $_SESSION['maintenance_mode'] = $this->state->get('system.maintenance_mode'); Chris@0: if ($form_state->getValue('maintenance_mode') == TRUE) { Chris@0: $this->state->set('system.maintenance_mode', TRUE); Chris@0: } Chris@0: Chris@0: if (!empty($_SESSION['update_manager_update_projects'])) { Chris@0: // Make sure the Updater registry is loaded. Chris@0: drupal_get_updaters(); Chris@0: Chris@0: $updates = []; Chris@0: $directory = _update_manager_extract_directory(); Chris@0: Chris@0: $projects = $_SESSION['update_manager_update_projects']; Chris@0: unset($_SESSION['update_manager_update_projects']); Chris@0: Chris@0: $project_real_location = NULL; Chris@0: foreach ($projects as $project => $url) { Chris@0: $project_location = $directory . '/' . $project; Chris@0: $updater = Updater::factory($project_location, $this->root); Chris@14: $project_real_location = \Drupal::service('file_system')->realpath($project_location); Chris@0: $updates[] = [ Chris@0: 'project' => $project, Chris@0: 'updater_name' => get_class($updater), Chris@0: 'local_url' => $project_real_location, Chris@0: ]; Chris@0: } Chris@0: Chris@0: // If the owner of the last directory we extracted is the same as the Chris@0: // owner of our configuration directory (e.g. sites/default) where we're Chris@0: // trying to install the code, there's no need to prompt for FTP/SSH Chris@0: // credentials. Instead, we instantiate a Drupal\Core\FileTransfer\Local Chris@0: // and invoke update_authorize_run_update() directly. Chris@0: if (fileowner($project_real_location) == fileowner($this->sitePath)) { Chris@0: $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize'); Chris@0: $filetransfer = new Local($this->root); Chris@0: $response = update_authorize_run_update($filetransfer, $updates); Chris@0: if ($response instanceof Response) { Chris@0: $form_state->setResponse($response); Chris@0: } Chris@0: } Chris@0: // Otherwise, go through the regular workflow to prompt for FTP/SSH Chris@0: // credentials and invoke update_authorize_run_update() indirectly with Chris@0: // whatever FileTransfer object authorize.php creates for us. Chris@0: else { Chris@0: // The page title must be passed here to ensure it is initially used Chris@0: // when authorize.php loads for the first time with the FTP/SSH Chris@0: // credentials form. Chris@0: system_authorized_init('update_authorize_run_update', __DIR__ . '/../../update.authorize.inc', [$updates], $this->t('Update manager')); Chris@0: $form_state->setRedirectUrl(system_authorized_get_url()); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }