Issue #2413695 by joelpittet: Modules getting installed in the theme directory if they don't have a *.module file
parent
35372e59ea
commit
dc52e8511b
|
@ -51,10 +51,9 @@ class Module extends Updater implements UpdaterInterface {
|
|||
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
|
||||
*/
|
||||
public static function canUpdateDirectory($directory) {
|
||||
if (file_scan_directory($directory, '/.*\.module$/')) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
$info = static::getExtensionInfo($directory);
|
||||
|
||||
return (isset($info['type']) && $info['type'] == 'module');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,11 +51,9 @@ class Theme extends Updater implements UpdaterInterface {
|
|||
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
|
||||
*/
|
||||
static function canUpdateDirectory($directory) {
|
||||
// This is a lousy test, but don't know how else to confirm it is a theme.
|
||||
if (file_scan_directory($directory, '/.*\.module$/')) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
$info = static::getExtensionInfo($directory);
|
||||
|
||||
return (isset($info['type']) && $info['type'] == 'theme');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,6 +111,28 @@ class Updater {
|
|||
return $info_file->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Extension information from directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* Directory to search in.
|
||||
*
|
||||
* @return array
|
||||
* Extension info.
|
||||
*
|
||||
* @throws \Drupal\Core\Updater\UpdaterException
|
||||
* If the info parser does not provide any info.
|
||||
*/
|
||||
protected static function getExtensionInfo($directory) {
|
||||
$info_file = static::findInfoFile($directory);
|
||||
$info = \Drupal::service('info_parser')->parse($info_file);
|
||||
if (empty($info)) {
|
||||
throw new UpdaterException(t('Unable to parse info file: %info_file.', ['%info_file' => $info_file]));
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the project directory (basename).
|
||||
*
|
||||
|
|
|
@ -45,8 +45,6 @@ interface UpdaterInterface {
|
|||
/**
|
||||
* Determines if the Updater can handle the project provided in $directory.
|
||||
*
|
||||
* @todo Provide something more rational here, like a project spec file.
|
||||
*
|
||||
* @param string $directory
|
||||
*
|
||||
* @return bool
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\update\Tests;
|
||||
|
||||
use Drupal\Core\Updater\Updater;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
|
@ -111,4 +112,16 @@ class UpdateUploadTest extends UpdateTestBase {
|
|||
$this->drupalGet('admin/update/ready');
|
||||
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests only an *.info.yml file are detected without supporting files.
|
||||
*/
|
||||
public function testUpdateDirectory() {
|
||||
$type = Updater::getUpdaterFromDirectory(\Drupal::root() . '/core/modules/update/tests/modules/aaa_update_test');
|
||||
$this->assertEqual($type, 'Drupal\\Core\\Updater\\Module', 'Detected a Module');
|
||||
|
||||
$type = Updater::getUpdaterFromDirectory(\Drupal::root() . '/core/modules/update/tests/themes/update_test_basetheme');
|
||||
$this->assertEqual($type, 'Drupal\\Core\\Updater\\Theme', 'Detected a Theme.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue