Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/update/src/Form/UpdateManagerInstall.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
133 /** | 133 /** |
134 * {@inheritdoc} | 134 * {@inheritdoc} |
135 */ | 135 */ |
136 public function submitForm(array &$form, FormStateInterface $form_state) { | 136 public function submitForm(array &$form, FormStateInterface $form_state) { |
137 $local_cache = NULL; | 137 $local_cache = NULL; |
138 $all_files = $this->getRequest()->files->get('files', []); | |
138 if ($form_state->getValue('project_url')) { | 139 if ($form_state->getValue('project_url')) { |
139 $local_cache = update_manager_file_get($form_state->getValue('project_url')); | 140 $local_cache = update_manager_file_get($form_state->getValue('project_url')); |
140 if (!$local_cache) { | 141 if (!$local_cache) { |
141 drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', ['%url' => $form_state->getValue('project_url')]), 'error'); | 142 $this->messenger()->addError($this->t('Unable to retrieve Drupal project from %url.', ['%url' => $form_state->getValue('project_url')])); |
142 return; | 143 return; |
143 } | 144 } |
144 } | 145 } |
145 elseif ($_FILES['files']['name']['project_upload']) { | 146 elseif (!empty($all_files['project_upload'])) { |
146 $validators = ['file_validate_extensions' => [archiver_get_extensions()]]; | 147 $validators = ['file_validate_extensions' => [archiver_get_extensions()]]; |
147 if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) { | 148 if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) { |
148 // Failed to upload the file. file_save_upload() calls | 149 // Failed to upload the file. file_save_upload() calls |
149 // drupal_set_message() on failure. | 150 // \Drupal\Core\Messenger\MessengerInterface::addError() on failure. |
150 return; | 151 return; |
151 } | 152 } |
152 $local_cache = $finfo->getFileUri(); | 153 $local_cache = $finfo->getFileUri(); |
153 } | 154 } |
154 | 155 |
155 $directory = _update_manager_extract_directory(); | 156 $directory = _update_manager_extract_directory(); |
156 try { | 157 try { |
157 $archive = update_manager_archive_extract($local_cache, $directory); | 158 $archive = update_manager_archive_extract($local_cache, $directory); |
158 } | 159 } |
159 catch (\Exception $e) { | 160 catch (\Exception $e) { |
160 drupal_set_message($e->getMessage(), 'error'); | 161 $this->messenger()->addError($e->getMessage()); |
161 return; | 162 return; |
162 } | 163 } |
163 | 164 |
164 $files = $archive->listContents(); | 165 $files = $archive->listContents(); |
165 if (!$files) { | 166 if (!$files) { |
166 drupal_set_message($this->t('Provided archive contains no files.'), 'error'); | 167 $this->messenger()->addError($this->t('Provided archive contains no files.')); |
167 return; | 168 return; |
168 } | 169 } |
169 | 170 |
170 // Unfortunately, we can only use the directory name to determine the | 171 // Unfortunately, we can only use the directory name to determine the |
171 // project name. Some archivers list the first file as the directory (i.e., | 172 // project name. Some archivers list the first file as the directory (i.e., |
172 // MODULE/) and others list an actual file (i.e., MODULE/README.TXT). | 173 // MODULE/) and others list an actual file (i.e., MODULE/README.TXT). |
173 $project = strtok($files[0], '/\\'); | 174 $project = strtok($files[0], '/\\'); |
174 | 175 |
175 $archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', [$project, $local_cache, $directory]); | 176 $archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', [$project, $local_cache, $directory]); |
176 if (!empty($archive_errors)) { | 177 if (!empty($archive_errors)) { |
177 drupal_set_message(array_shift($archive_errors), 'error'); | 178 $this->messenger()->addError(array_shift($archive_errors)); |
178 // @todo: Fix me in D8: We need a way to set multiple errors on the same | 179 // @todo: Fix me in D8: We need a way to set multiple errors on the same |
179 // form element and have all of them appear! | 180 // form element and have all of them appear! |
180 if (!empty($archive_errors)) { | 181 if (!empty($archive_errors)) { |
181 foreach ($archive_errors as $error) { | 182 foreach ($archive_errors as $error) { |
182 drupal_set_message($error, 'error'); | 183 $this->messenger()->addError($error); |
183 } | 184 } |
184 } | 185 } |
185 return; | 186 return; |
186 } | 187 } |
187 | 188 |
191 $project_location = $directory . '/' . $project; | 192 $project_location = $directory . '/' . $project; |
192 try { | 193 try { |
193 $updater = Updater::factory($project_location, $this->root); | 194 $updater = Updater::factory($project_location, $this->root); |
194 } | 195 } |
195 catch (\Exception $e) { | 196 catch (\Exception $e) { |
196 drupal_set_message($e->getMessage(), 'error'); | 197 $this->messenger()->addError($e->getMessage()); |
197 return; | 198 return; |
198 } | 199 } |
199 | 200 |
200 try { | 201 try { |
201 $project_title = Updater::getProjectTitle($project_location); | 202 $project_title = Updater::getProjectTitle($project_location); |
202 } | 203 } |
203 catch (\Exception $e) { | 204 catch (\Exception $e) { |
204 drupal_set_message($e->getMessage(), 'error'); | 205 $this->messenger()->addError($e->getMessage()); |
205 return; | 206 return; |
206 } | 207 } |
207 | 208 |
208 if (!$project_title) { | 209 if (!$project_title) { |
209 drupal_set_message($this->t('Unable to determine %project name.', ['%project' => $project]), 'error'); | 210 $this->messenger()->addError($this->t('Unable to determine %project name.', ['%project' => $project])); |
210 } | 211 } |
211 | 212 |
212 if ($updater->isInstalled()) { | 213 if ($updater->isInstalled()) { |
213 drupal_set_message($this->t('%project is already installed.', ['%project' => $project_title]), 'error'); | 214 $this->messenger()->addError($this->t('%project is already installed.', ['%project' => $project_title])); |
214 return; | 215 return; |
215 } | 216 } |
216 | 217 |
217 $project_real_location = \Drupal::service('file_system')->realpath($project_location); | 218 $project_real_location = \Drupal::service('file_system')->realpath($project_location); |
218 $arguments = [ | 219 $arguments = [ |