Skip to content

Commit

Permalink
Try out Drupal 9 support (#4227)
Browse files Browse the repository at this point in the history
* Try out Drupal 9 support

* Translate from "9.x" to "all" to keep pace with drupalorg infrastructure changes to update xml service.

* Use our own private copy of the symfony/yaml parser to avoid variability with Drupal versions.

* Fix a few more tests

* Make modules enablable

* Make a role class for Drupal 9 (works like Drupal 8).

* Queue class for Drupal 9

* Skip tests that use devel, add test fixtures for some other tests.

* Add Drupal 9 cache include file

* Skip testing of --sanitize option on Drupal 9; it is broken for some reason. Fix the cache test (spurrious failure, did not account for Drupal 9).
  • Loading branch information
greg-1-anderson committed Oct 24, 2019
1 parent 49cee4d commit 2617d56
Show file tree
Hide file tree
Showing 42 changed files with 2,438 additions and 19 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ env:

matrix:
include:
# D9.0.x
- php: 7.2
env: 'UNISH_DRUPAL_MAJOR_VERSION=9 UNISH_DRUPAL_MINOR_VERSION=0.x-dev'

# D8.8.x
- php: 7.2
env: 'UNISH_DRUPAL_MAJOR_VERSION=8 UNISH_DRUPAL_MINOR_VERSION=8.0-alpha1'

# D8.7.x
- php: 7.0
env: 'UNISH_DRUPAL_MAJOR_VERSION=8 UNISH_DRUPAL_MINOR_VERSION=7.3'
env: 'UNISH_DRUPAL_MAJOR_VERSION=8 UNISH_DRUPAL_MINOR_VERSION=7.8'

# D8.6.x
- php: 7.0
Expand Down
2 changes: 1 addition & 1 deletion commands/core/config.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Drupal\Core\Config\FileStorage;
use Drupal\Component\Utility\NestedArray;
use Drush\Config\StorageWrapper;
use Drush\Config\CoreExtensionFilter;
use Symfony\Component\Yaml\Parser;
use Drush\Internal\Symfony\Yaml\Parser;

/**
* Implementation of hook_drush_help().
Expand Down
87 changes: 87 additions & 0 deletions commands/core/drupal/cache_9.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* @file
* Engine for the cache commands.
*/

use Drupal\Core\Cache\Cache;

function _drush_cache_command_get($cid, $bin) {
if (is_null($bin)) {
$bin = _drush_cache_bin_default();
}
return \Drupal::cache($bin)->get($cid);
}

/**
* The default bin.
*
* @return string
*/
function _drush_cache_bin_default() {
return 'default';
}

function _drush_cache_command_set($cid, $data, $bin, $expire, $tags) {
if (is_null($bin)) {
$bin = _drush_cache_bin_default();
}

// Convert the "expire" argument to a valid value for Drupal's cache_set().
if ($expire == 'CACHE_TEMPORARY') {
$expire = Cache::TEMPORARY;
}
if (!isset($expire) || $expire == 'CACHE_PERMANENT') {
$expire = Cache::PERMANENT;
}

return \Drupal::cache($bin)->set($cid, $data, $expire, $tags);
}

function _drush_cache_clear_types($include_bootstrapped_types) {
$types = array(
'drush' => 'drush_cache_clear_drush',
);
if ($include_bootstrapped_types) {
$types += array(
'theme-registry' => 'drush_cache_clear_theme_registry',
'router' => 'drush_cache_clear_router',
'css-js' => 'drush_cache_clear_css_js',
'module-list' => 'drush_get_modules',
'theme-list' => 'drush_get_themes',
'render' => 'drush_cache_clear_render',
);
}
return $types;
}

function drush_cache_clear_theme_registry() {
\Drupal::service('theme.registry')->reset();
}

function drush_cache_clear_router() {
/** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
$router_builder = \Drupal::service('router.builder');
$router_builder->rebuild();
}

function drush_cache_clear_css_js() {
_drupal_flush_css_js();
drupal_clear_css_cache();
drupal_clear_js_cache();
}

/**
* Clear the cache of the block output.
*/
function drush_cache_clear_block() {
// There is no distinct block cache in D8. See https://github.com/drush-ops/drush/issues/1531.
// \Drupal::cache('block')->deleteAll();
}

/**
* Clears the render cache entries.
*/
function drush_cache_clear_render() {
Cache::invalidateTags(['rendered']);
}
2 changes: 1 addition & 1 deletion commands/core/outputformat/yaml.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use Symfony\Component\Yaml\Dumper;
use Drush\Internal\Symfony\Yaml\Dumper;

/**
* Output formatter 'yaml'
Expand Down
2 changes: 1 addition & 1 deletion commands/make/make.utilities.inc
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ function _make_determine_format($data) {
return $parsed;
}
}
catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
catch (\Drush\Internal\Symfony\Yaml\Exception\ParseException $e) {
// Note that an exception was thrown, and display after .ini parsing.
$yaml_parse_exception = $e;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ function drush_value_format($value, $format) {
break;

case 'yaml':
$value = \Symfony\Component\Yaml\Yaml::parse($value, FALSE, TRUE);
$value = \Drush\Internal\Symfony\Yaml\Yaml::parse($value, FALSE, TRUE);
break;
}
return $value;
Expand Down
8 changes: 8 additions & 0 deletions includes/environment.inc
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,14 @@ function drush_extension_get_path($info) {
* @return FALSE if the extension is compatible.
*/
function drush_extension_check_incompatibility($file) {
// TODO: what is the right way to detect core modules?
if (isset($file->info['package']) && ($file->info['package'] == 'Core')) {
return FALSE;
}
// TODO: validate core_version_requirement
if (isset($file->info['core_version_requirement'])) {
return FALSE;
}
if (!isset($file->info['core']) || $file->info['core'] != drush_get_drupal_core_compatibility()) {
return 'Drupal';
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Drush/Boot/DrupalBoot8.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

use Drush\Log\LogLevel;

/**
* Drupal 8 and Drupal 9 are so similar at the moment that we will use
* the same bootstrap class for each.
*/
class DrupalBoot8 extends DrupalBoot {

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Drush/Make/Parser/ParserYaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Drush\Make\Parser;

use Symfony\Component\Yaml\Yaml;
use Drush\Internal\Symfony\Yaml\Yaml;

class ParserYaml implements ParserInterface {

Expand Down
11 changes: 11 additions & 0 deletions lib/Drush/Queue/Queue9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Drush\Queue;

use Drush\Log\LogLevel;
use Drupal\Core\Queue\QueueWorkerManager;
use Drupal\Core\Queue\RequeueException;
use Drupal\Core\Queue\SuspendQueueException;

class Queue9 extends Queue8 {
}
8 changes: 8 additions & 0 deletions lib/Drush/Role/Role9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Drush\Role;

use Drupal\user\Entity\Role;

class Role9 extends Role8 {
}
7 changes: 7 additions & 0 deletions lib/Drush/Sql/Sql9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Drush\Sql;

use Drupal\Core\Database\Database;

class Sql9 extends Sql8 {
}
6 changes: 5 additions & 1 deletion lib/Drush/UpdateService/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public static function getInstance(array $request, $cache_duration = ReleaseInfo
*/
public static function buildFetchUrl(array $request) {
$status_url = isset($request['status url']) ? $request['status url'] : ReleaseInfo::DEFAULT_URL;
return $status_url . '/' . $request['name'] . '/' . $request['drupal_version'];
$drupal_version = $request['drupal_version'];
if ($drupal_version == '9.x') {
$drupal_version = 'all';
}
return $status_url . '/' . $request['name'] . '/' . $drupal_version;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions lib/Drush/User/User9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php


namespace Drush\User;

use Drupal\user\Entity\User;

class User9 extends User8 {
}
7 changes: 7 additions & 0 deletions lib/Drush/User/UserSingle9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Drush\User;

class UserSingle9 extends UserSingle8 {

}
28 changes: 28 additions & 0 deletions src/Internal/Symfony/Yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CHANGELOG
=========

2.8.0
-----

* Deprecated usage of a colon in an unquoted mapping value
* Deprecated usage of @, \`, | and > at the beginning of an unquoted string
* When surrounding strings with double-quotes, you must now escape `\` characters. Not
escaping those characters (when surrounded by double-quotes) is deprecated.

Before:

```yml
class: "Foo\Var"
```

After:

```yml
class: "Foo\\Var"
```

2.1.0
-----

* Yaml::parse() does not evaluate loaded files as PHP files by default
anymore (call Yaml::enablePhpParsing() to get back the old behavior)
77 changes: 77 additions & 0 deletions src/Internal/Symfony/Yaml/Dumper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Drush\Internal\Symfony\Yaml;

/**
* Dumper dumps PHP variables to YAML strings.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Dumper
{
/**
* The amount of spaces to use for indentation of nested nodes.
*
* @var int
*/
protected $indentation = 4;

/**
* Sets the indentation.
*
* @param int $num The amount of spaces to use for indentation of nested nodes
*/
public function setIndentation($num)
{
if ($num < 1) {
throw new \InvalidArgumentException('The indentation must be greater than zero.');
}

$this->indentation = (int) $num;
}

/**
* Dumps a PHP value to YAML.
*
* @param mixed $input The PHP value
* @param int $inline The level where you switch to inline YAML
* @param int $indent The level of indentation (used internally)
* @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport True if object support is enabled, false otherwise
*
* @return string The YAML representation of the PHP value
*/
public function dump($input, $inline = 0, $indent = 0, $exceptionOnInvalidType = false, $objectSupport = false)
{
$output = '';
$prefix = $indent ? str_repeat(' ', $indent) : '';

if ($inline <= 0 || !\is_array($input) || empty($input)) {
$output .= $prefix.Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
} else {
$isAHash = Inline::isHash($input);

foreach ($input as $key => $value) {
$willBeInlined = $inline - 1 <= 0 || !\is_array($value) || empty($value);

$output .= sprintf('%s%s%s%s',
$prefix,
$isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-',
$willBeInlined ? ' ' : "\n",
$this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)
).($willBeInlined ? "\n" : '');
}
}

return $output;
}
}

0 comments on commit 2617d56

Please sign in to comment.