diff --git a/doc/80-Upgrading.md b/doc/80-Upgrading.md index efbc071ca..26b6528d6 100644 --- a/doc/80-Upgrading.md +++ b/doc/80-Upgrading.md @@ -3,6 +3,12 @@ Specific version upgrades are described below. Please note that upgrades are incremental. An upgrade from v2.6 to v2.8 requires to follow the instructions for v2.7 too. +## Upgrading to Icinga Web 2 2.10.x + +**Framework changes affecting third-party code** + +* Asset support for modules (#3961) introduced with v2.8 has now been removed. + ## Upgrading to Icinga Web 2 2.9.1 **Database Schema** diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index 22d1debd7..0a7e5799f 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -18,8 +18,6 @@ use Icinga\Web\Widget; use ipl\I18n\GettextTranslator; use ipl\I18n\StaticTranslator; use ipl\I18n\Translation; -use RecursiveDirectoryIterator; -use RecursiveIteratorIterator; use Zend_Controller_Router_Route; use Zend_Controller_Router_Route_Abstract; use Zend_Controller_Router_Route_Regex; @@ -50,13 +48,6 @@ class Module */ private $basedir; - /** - * Directory for assets - * - * @var string - */ - private $assetDir; - /** * Directory for styles * @@ -204,34 +195,6 @@ class Module */ protected $jsFiles = array(); - /** - * Globally provided CSS assets - * - * @var array - */ - protected $cssAssets = []; - - /** - * Globally provided JS assets - * - * @var array - */ - protected $jsAssets = []; - - /** - * Required CSS assets - * - * @var array - */ - protected $cssRequires = []; - - /** - * Required JS assets - * - * @var array - */ - protected $jsRequires = []; - /** * Routes to add to the route chain * @@ -295,7 +258,6 @@ class Module $this->app = $app; $this->name = $name; $this->basedir = $basedir; - $this->assetDir = $basedir . '/asset'; $this->cssdir = $basedir . '/public/css'; $this->jsdir = $basedir . '/public/js'; $this->libdir = $basedir . '/library'; @@ -487,7 +449,6 @@ class Module return false; } $this->registerWebIntegration(); - $this->registerAssets(); $this->registered = true; return true; @@ -537,164 +498,6 @@ class Module return $manager->getModule($name); } - /** - * Provide a static CSS asset which can be required by other modules - * - * @param string $path The path, relative to the module's base - * - * @return $this - */ - protected function provideCssAsset($path) - { - $fullPath = join(DIRECTORY_SEPARATOR, [$this->basedir, $path]); - $this->cssAssets[] = $fullPath; - $this->cssRequires[] = $fullPath; // A module should not have to require its own assets - - return $this; - } - - /** - * Get the CSS assets provided by this module - * - * @return array - */ - public function getCssAssets() - { - return $this->cssAssets; - } - - /** - * Require CSS from a different module - * - * @param string $path The file's path, relative to the module's asset or base directory - * @param string $from The module's name - * - * @deprecated Deprecated with v2.9, don't use and depend on a library instead - * @return $this - */ - protected function requireCssFile($path, $from) - { - $module = self::get($from); - $cssAssetDir = join(DIRECTORY_SEPARATOR, [$module->assetDir, 'css']); - foreach ($module->getCssAssets() as $assetPath) { - if (substr($assetPath, 0, strlen($cssAssetDir)) === $cssAssetDir) { - $relativePath = ltrim(substr($assetPath, strlen($cssAssetDir)), '/\\'); - } else { - $relativePath = ltrim(substr($assetPath, strlen($module->basedir)), '/\\'); - } - - if ($path === $relativePath) { - $this->cssRequires[] = $assetPath; - break; // Exact match, won't match again.. - } elseif (fnmatch($path, $relativePath)) { - $this->cssRequires[] = $assetPath; - } - } - - return $this; - } - - /** - * Check whether this module requires CSS from a different module - * - * @return bool - */ - public function requiresCss() - { - $this->launchConfigScript(); - return ! empty($this->cssRequires); - } - - /** - * List the CSS assets required by this module - * - * @return array - */ - public function getCssRequires() - { - $this->launchConfigScript(); - return $this->cssRequires; - } - - /** - * Provide a static Javascript asset which can be required by other modules - * - * @param string $path The path, relative to the module's base - * - * @return $this - */ - protected function provideJsAsset($path) - { - $fullPath = join(DIRECTORY_SEPARATOR, [$this->basedir, $path]); - $this->jsAssets[] = $fullPath; - $this->jsRequires[] = $fullPath; // A module should not have to require its own assets - - return $this; - } - - /** - * Get the Javascript assets provided by this module - * - * @return array - */ - public function getJsAssets() - { - return $this->jsAssets; - } - - /** - * Require Javascript from a different module - * - * @param string $path The file's path, relative to the module's asset or base directory - * @param string $from The module's name - * - * @deprecated Deprecated with v2.9, don't use and depend on a library instead - * @return $this - */ - protected function requireJsFile($path, $from) - { - $module = self::get($from); - $jsAssetDir = join(DIRECTORY_SEPARATOR, [$module->assetDir, 'js']); - foreach ($module->getJsAssets() as $assetPath) { - if (substr($assetPath, 0, strlen($jsAssetDir)) === $jsAssetDir) { - $relativePath = ltrim(substr($assetPath, strlen($jsAssetDir)), '/\\'); - } else { - $relativePath = ltrim(substr($assetPath, strlen($module->basedir)), '/\\'); - } - - if ($path === $relativePath) { - $this->jsRequires[] = $assetPath; - break; // Exact match, won't match again.. - } elseif (fnmatch($path, $relativePath)) { - $this->jsRequires[] = $assetPath; - } - } - - return $this; - } - - /** - * Check whether this module requires Javascript from a different module - * - * @return bool - */ - public function requiresJs() - { - $this->launchConfigScript(); - return ! empty($this->jsRequires); - } - - /** - * List the Javascript assets required by this module - * - * @return array - */ - public function getJsRequires() - { - $this->launchConfigScript(); - return $this->jsRequires; - } - /** * Provide an additional CSS/LESS file * @@ -1081,16 +884,6 @@ class Module return $this->jsdir; } - /** - * Get the module's JS asset directory - * - * @return string - */ - public function getJsAssetDir() - { - return join(DIRECTORY_SEPARATOR, [$this->assetDir, 'js']); - } - /** * Get the module's controller directory * @@ -1442,40 +1235,6 @@ class Module return $this; } - /** - * Register this module's assets - * - * @return $this - */ - protected function registerAssets() - { - if (! is_dir($this->assetDir)) { - return $this; - } - - $listAssets = function ($type) { - $dir = join(DIRECTORY_SEPARATOR, [$this->assetDir, $type]); - if (! is_dir($dir)) { - return []; - } - - return new RecursiveIteratorIterator(new RecursiveDirectoryIterator( - $dir, - RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS - )); - }; - - foreach ($listAssets('css') as $assetPath) { - $this->provideCssAsset(ltrim(substr($assetPath, strlen($this->basedir)), '/\\')); - } - - foreach ($listAssets('js') as $assetPath) { - $this->provideJsAsset(ltrim(substr($assetPath, strlen($this->basedir)), '/\\')); - } - - return $this; - } - /** * Bind text domain for i18n * diff --git a/library/Icinga/Web/JavaScript.php b/library/Icinga/Web/JavaScript.php index 69b51576f..cce48d866 100644 --- a/library/Icinga/Web/JavaScript.php +++ b/library/Icinga/Web/JavaScript.php @@ -118,12 +118,6 @@ class JavaScript } } } - - $assetDir = $module->getJsAssetDir(); - foreach ($module->getJsAssets() as $path) { - $moduleFiles[$name][$assetDir][] = $path; - $files[] = $path; - } } $request = Icinga::app()->getRequest(); diff --git a/library/Icinga/Web/LessCompiler.php b/library/Icinga/Web/LessCompiler.php index e0459bf95..5ed5d5bae 100644 --- a/library/Icinga/Web/LessCompiler.php +++ b/library/Icinga/Web/LessCompiler.php @@ -35,13 +35,6 @@ class LessCompiler */ protected $moduleLessFiles = array(); - /** - * Array of module names indexed by LESS asset paths - * - * @var array - */ - protected $moduleRequires = []; - /** * LESS source * @@ -103,20 +96,6 @@ class LessCompiler return $this; } - /** - * Add a LESS asset requirement - * - * @param string $moduleName - * @param string $lessFile - * - * @return $this - */ - public function addModuleRequire($moduleName, $lessFile) - { - $this->moduleRequires[$lessFile][] = $moduleName; - return $this; - } - /** * Get the list of LESS files added to the compiler * @@ -130,8 +109,6 @@ class LessCompiler $lessFiles = array_merge($lessFiles, $moduleLessFiles); } - $lessFiles = array_merge($lessFiles, array_keys($this->moduleRequires)); - if ($this->theme !== null) { $lessFiles[] = $this->theme; } @@ -204,13 +181,6 @@ class LessCompiler foreach ($this->moduleLessFiles as $moduleName => $moduleLessFiles) { $moduleCss .= '.icinga-module.module-' . $moduleName . ' {'; - // TODO: Import these. - foreach ($this->moduleRequires as $requiredFile => $modules) { - if (in_array($moduleName, $modules, true)) { - $moduleCss .= file_get_contents($requiredFile); - } - } - foreach ($moduleLessFiles as $moduleLessFile) { $content = file_get_contents($moduleLessFile); diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index 753a423ad..f7134723a 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -146,12 +146,6 @@ class StyleSheet $this->lessCompiler->addModuleLessFile($moduleName, $lessFilePath); } } - - if ($module->requiresCss()) { - foreach ($module->getCssRequires() as $lessFilePath) { - $this->lessCompiler->addModuleRequire($moduleName, $lessFilePath); - } - } } $themingConfig = $this->app->getConfig()->getSection('themes');