Skip to content
Snippets Groups Projects
Commit dc52e851 authored by catch's avatar catch
Browse files

Issue #2413695 by joelpittet: Modules getting installed in the theme directory...

Issue #2413695 by joelpittet: Modules getting installed in the theme directory if they don't have a *.module file
parent 35372e59
No related branches found
No related tags found
No related merge requests found
...@@ -51,10 +51,9 @@ public function isInstalled() { ...@@ -51,10 +51,9 @@ public function isInstalled() {
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory(). * Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
*/ */
public static function canUpdateDirectory($directory) { public static function canUpdateDirectory($directory) {
if (file_scan_directory($directory, '/.*\.module$/')) { $info = static::getExtensionInfo($directory);
return TRUE;
} return (isset($info['type']) && $info['type'] == 'module');
return FALSE;
} }
/** /**
......
...@@ -51,11 +51,9 @@ public function isInstalled() { ...@@ -51,11 +51,9 @@ public function isInstalled() {
* Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory(). * Implements Drupal\Core\Updater\UpdaterInterface::canUpdateDirectory().
*/ */
static function canUpdateDirectory($directory) { static function canUpdateDirectory($directory) {
// This is a lousy test, but don't know how else to confirm it is a theme. $info = static::getExtensionInfo($directory);
if (file_scan_directory($directory, '/.*\.module$/')) {
return FALSE; return (isset($info['type']) && $info['type'] == 'theme');
}
return TRUE;
} }
/** /**
......
...@@ -111,6 +111,28 @@ public static function findInfoFile($directory) { ...@@ -111,6 +111,28 @@ public static function findInfoFile($directory) {
return $info_file->uri; 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). * Gets the name of the project directory (basename).
* *
......
...@@ -45,8 +45,6 @@ public function getInstallDirectory(); ...@@ -45,8 +45,6 @@ public function getInstallDirectory();
/** /**
* Determines if the Updater can handle the project provided in $directory. * 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 * @param string $directory
* *
* @return bool * @return bool
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\update\Tests; namespace Drupal\update\Tests;
use Drupal\Core\Updater\Updater;
use Drupal\Core\Url; use Drupal\Core\Url;
/** /**
...@@ -111,4 +112,16 @@ function testUpdateManagerCoreSecurityUpdateMessages() { ...@@ -111,4 +112,16 @@ function testUpdateManagerCoreSecurityUpdateMessages() {
$this->drupalGet('admin/update/ready'); $this->drupalGet('admin/update/ready');
$this->assertNoText(t('There is a security update available for your version of Drupal.')); $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.');
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment