Commit dc52e851 authored by catch's avatar catch

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
......@@ -51,10 +51,9 @@ public function isInstalled() {
* 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 @@ public function isInstalled() {
* 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 @@ public static function findInfoFile($directory) {
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 @@ public function getInstallDirectory();
/**
* 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 @@ function testUpdateManagerCoreSecurityUpdateMessages() {
$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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment