Skip to content
Snippets Groups Projects

Issue #3298889: Make \Drupal\package_manager_test_api\ApiController more easily extendable

3 files
+ 50
55
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -2,64 +2,43 @@
namespace Drupal\automatic_updates_test;
use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\Component\Utility\Environment;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\HtmlResponse;
use Symfony\Component\HttpFoundation\Response;
use Drupal\package_manager_test_api\ApiController as PackageManagerApiController;
use Symfony\Component\HttpFoundation\Request;
class TestController extends ControllerBase {
class TestController extends PackageManagerApiController {
/**
* Performs an in-place update to a given version of Drupal core.
*
* This executes the update immediately, in one request, without using the
* batch system or cron as wrappers.
*
* @param string $to_version
* @var string
*/
protected $finished_route = 'automatic_updates_test.finish';
/**
* @var string
* The version of core to update to.
*
* @return \Symfony\Component\HttpFoundation\Response
* The response object.
*/
public function update(string $to_version): Response {
private $to_version;
/**
* Sets $to_version.
*/
public function update(string $to_version): void {
$this->to_version = $to_version;
}
/**
* {@inheritdoc}
*/
protected function createAndApplyStage(Request $request): string {
// Let it take as long as it needs.
Environment::setTimeLimit(0);
/** @var \Drupal\automatic_updates\Updater $updater */
$updater = \Drupal::service('automatic_updates.updater');
try {
$updater->begin(['drupal' => $to_version]);
$updater->stage();
$updater->apply();
$updater->postApply();
$updater->destroy();
// The code base has been updated, but as far as the PHP runtime is
// concerned, \Drupal::VERSION refers to the old version, until the next
// request. So check if the updated version is in Drupal.php and return
// a clear indication of whether it's there or not.
$drupal_php = file_get_contents(\Drupal::root() . '/core/lib/Drupal.php');
if (str_contains($drupal_php, "const VERSION = '$to_version';")) {
$content = "$to_version found in Drupal.php";
}
else {
$content = "$to_version not found in Drupal.php";
}
$status = 200;
}
catch (UpdateException $e) {
$messages = [];
foreach ($e->getResults() as $result) {
if ($summary = $result->getSummary()) {
$messages[] = $summary;
}
$messages = array_merge($messages, $result->getMessages());
}
$content = implode('<br />', $messages);
$status = 500;
}
return new HtmlResponse($content, $status);
$id = $updater->begin(['drupal' => $this->to_version]);
$updater->stage();
$updater->apply();
return $id;
}
}
Loading