From d0251f049325e29a44ac13eb6b91c9ec94a0c1e0 Mon Sep 17 00:00:00 2001 From: Mayur Gondhkar Date: Thu, 7 Jul 2022 15:48:14 +1000 Subject: [PATCH 1/2] [SDPA-6324] Deprecated Composer v1 plugins breaking builds --- composer.dev.json | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/composer.dev.json b/composer.dev.json index 0f9727a..af8c2de 100644 --- a/composer.dev.json +++ b/composer.dev.json @@ -30,11 +30,6 @@ "phpspec/prophecy-phpunit":"^2", "weitzman/drupal-test-traits": "^1.5" }, - "autoload": { - "classmap": [ - "scripts/composer/" - ] - }, "prefer-stable": true, "minimum-stability": "dev", "config": { @@ -441,24 +436,6 @@ "url": "https://github.com/dpc-sdp/token_conditions.git" } }, - "scripts": { - "pre-install-cmd": [ - "DrupalProject\\composer\\ScriptHandler::checkComposerVersion" - ], - "pre-update-cmd": [ - "DrupalProject\\composer\\ScriptHandler::checkComposerVersion" - ], - "post-install-cmd": [ - "composer drupal:scaffold", - "DrupalProject\\composer\\ScriptHandler::createRequiredFiles", - "Utilities\\composer\\DrupalSettings::create" - ], - "post-update-cmd": [ - "composer drupal:scaffold", - "DrupalProject\\composer\\ScriptHandler::createRequiredFiles", - "Utilities\\composer\\DrupalSettings::create" - ] - }, "extra": { "drupal-scaffold": { "allowed-packages": [ From c3c9cea623fcf5042c1f45092f52152c58720e36 Mon Sep 17 00:00:00 2001 From: Mayur Gondhkar Date: Thu, 7 Jul 2022 15:54:00 +1000 Subject: [PATCH 2/2] Remove DrupalSettings and ScriptHandler scripts --- scripts/composer/DrupalSettings.php | 216 ---------------------------- scripts/composer/ScriptHandler.php | 138 ------------------ 2 files changed, 354 deletions(-) delete mode 100644 scripts/composer/DrupalSettings.php delete mode 100644 scripts/composer/ScriptHandler.php diff --git a/scripts/composer/DrupalSettings.php b/scripts/composer/DrupalSettings.php deleted file mode 100644 index afb8386..0000000 --- a/scripts/composer/DrupalSettings.php +++ /dev/null @@ -1,216 +0,0 @@ -locateRoot(getcwd()); - $drupalRoot = $drupalFinder->getDrupalRoot(); - - $standard_settings_file = $drupalRoot . '/sites/default/settings.php'; - $generated_settings_file_name = 'settings.generated.php'; - - $defaults = [ - 'mysql_database' => 'drupal', - 'mysql_user' => 'drupal', - 'mysql_password' => 'drupal', - 'mysql_host' => 'localhost', - 'mysql_port' => '', - 'mysql_prefix' => '', - 'settings_path' => $drupalRoot . '/sites/default/' . $generated_settings_file_name, - ]; - - $options = self::extractEnvironmentVariables(array_keys($defaults)) - + self::extractCliOptions($event->getArguments(), array_keys($defaults)) - + $defaults; - - if (!$fs->exists($options['settings_path'])) { - $content = self::getDefaultDrupalSettingsContent($options); - $fs->dumpFile($options['settings_path'], $content); - $fs->chmod($options['settings_path'], 0644); - $event->getIO()->write(sprintf('Created file %s with chmod 0644', $options['settings_path'] . PHP_EOL . $content)); - } - else { - $event->getIO()->write(sprintf('Skipping creation of Drupal settings file "%s" - file already exists', $options['settings_path'])); - } - - // Add inclusion of this file to standard settings file if it exists and - // such inclusion has not been added previously. - if ($fs->exists($options['settings_path']) && $fs->exists($standard_settings_file)) { - if (strpos(file_get_contents($standard_settings_file), $generated_settings_file_name) === FALSE) { - $string = <<getIO()->write(sprintf('Added inclusion of generated settings file %s to %s', $generated_settings_file_name, $standard_settings_file)); - } - else { - $event->getIO()->write(sprintf('Skipped inclusion of generated settings file %s to %s - inclusion already present', $generated_settings_file_name, $standard_settings_file)); - } - } - } - - /** - * Delete Drupal settings file. - */ - public static function delete(Event $event) { - $defaults = [ - 'settings_path' => 'docroot/sites/default/settings.generated.php', - ]; - - $options = self::extractEnvironmentVariables(array_keys($defaults)) - + self::extractCliOptions($event->getArguments(), array_keys($defaults)) - + $defaults; - - $fs = new Filesystem(); - if (!$fs->exists($options['settings_path'])) { - $event->getIO()->write('Skipping deletion of Drupal settings file - file does not exists'); - } - else { - $fs->remove($options['settings_path']); - $event->getIO()->write(sprintf('Deleted file %s', $options['settings_path'])); - } - } - - /** - * Return content for default Drupal settings file. - */ - protected static function getDefaultDrupalSettingsContent($options) { - return << - [ - 'default' => - [ - 'database' => '${options['mysql_database']}', - 'username' => '${options['mysql_user']}', - 'password' => '${options['mysql_password']}', - 'host' => '${options['mysql_host']}', - 'port' => '${options['mysql_port']}', - 'driver' => 'mysql', - 'prefix' => '${options['mysql_prefix']}', - ], - ], -]; - -// Allow installing extensions under tests directory. -\$settings['extension_discovery_scan_tests'] = TRUE; - -FILE; - } - - /** - * Extract options from environment variables. - * - * @param bool|array $allowed - * Array of allowed options. - * - * @return array - * Array of extracted options. - */ - protected static function extractEnvironmentVariables(array $allowed) { - $options = []; - - $dotenv = Dotenv::createImmutable(__DIR__ . '/../..'); - $dotenv->load(); - - foreach ($allowed as $name) { - $value = getenv(strtoupper($name)); - if ($value !== FALSE) { - $options[$name] = $value; - } - } - - return $options; - } - - /** - * Extract options from CLI arguments. - * - * @param array $arguments - * Array of arguments. - * @param bool|array $allowed - * Array of allowed options. - * - * @return array - * Array of extracted options. - */ - protected static function extractCliOptions(array $arguments, array $allowed) { - $options = []; - - foreach ($arguments as $argument) { - if (strpos($argument, '--') === 0) { - list($name, $value) = explode('=', $argument); - $name = substr($name, strlen('--')); - $options[$name] = $value; - if (array_key_exists($name, $allowed) && !is_null($value)) { - $options[$name] = $value; - } - } - } - - return $options; - } - - /** - * Appends content to an existing file. - * - * Polyfill for older versions of Filesystem shipped with Composer phar. - * - * @param string $filename - * The file to which to append content. - * @param string $content - * The content to append. - * - * @throws \Symfony\Component\Filesystem\Exception\IOException - * If the file is not writable. - */ - protected static function appendToFile($filename, $content) { - $fs = new Filesystem(); - - $dir = \dirname($filename); - - if (!is_dir($dir)) { - $fs->mkdir($dir); - } - - if (!is_writable($dir)) { - throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, NULL, $dir); - } - - if (FALSE === @file_put_contents($filename, $content, FILE_APPEND)) { - throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, NULL, $filename); - } - } - -} diff --git a/scripts/composer/ScriptHandler.php b/scripts/composer/ScriptHandler.php deleted file mode 100644 index 32a0eaf..0000000 --- a/scripts/composer/ScriptHandler.php +++ /dev/null @@ -1,138 +0,0 @@ -locateRoot(getcwd()); - $drupalRoot = $drupalFinder->getDrupalRoot(); - - $dirs = [ - 'modules', - 'profiles', - 'themes', - ]; - - // Required for unit testing. - foreach ($dirs as $dir) { - if (!$fs->exists($drupalRoot . '/' . $dir)) { - $fs->mkdir($drupalRoot . '/' . $dir); - $fs->touch($drupalRoot . '/' . $dir . '/.gitkeep'); - } - } - - // Prepare the settings file for installation. - if ($fs->exists($drupalRoot . '/sites/default/default.settings.php') && !$fs->exists($drupalRoot . '/sites/default/settings.php')) { - $fs->copy($drupalRoot . '/sites/default/default.settings.php', $drupalRoot . '/sites/default/settings.php'); - $event->getIO()->write('Created a sites/default/settings.php file'); - } - - if (!$fs->exists($drupalRoot . '/sites/default/settings.php')) { - $event->getIO()->writeError('Settings file not found'); - exit(1); - } - - $fs->chmod($drupalRoot . '/sites/default', 0777); - $fs->chmod($drupalRoot . '/sites/default/settings.php', 0666); - - $configPath = Path::makeRelative($drupalFinder->getComposerRoot() . '/config/default', $drupalRoot); - $settings_string = <<exists($drupalRoot . '/sites/default/files')) { - $oldmask = umask(0); - $fs->mkdir($drupalRoot . '/sites/default/files', 0777); - umask($oldmask); - $event->getIO()->write('Created a sites/default/files directory with chmod 0777'); - } - } - - /** - * Checks if the installed version of Composer is compatible. - * - * Composer 1.0.0 and higher consider a `composer install` without having a - * lock file present as equal to `composer update`. We do not ship with a lock - * file to avoid merge conflicts downstream, meaning that if a project is - * installed with an older version of Composer the scaffolding of Drupal will - * not be triggered. We check this here instead of in drupal-scaffold to be - * able to give immediate feedback to the end user, rather than failing the - * installation after going through the lengthy process of compiling and - * downloading the Composer dependencies. - * - * @see https://github.com/composer/composer/pull/5035 - */ - public static function checkComposerVersion(Event $event) { - $composer = $event->getComposer(); - $io = $event->getIO(); - - $version = $composer::VERSION; - - // The dev-channel of composer uses the git revision as version number, - // try to the branch alias instead. - if (preg_match('/^[0-9a-f]{40}$/i', $version)) { - $version = $composer::BRANCH_ALIAS_VERSION; - } - - // If Composer is installed through git we have no easy way to determine if - // it is new enough, just display a warning. - if ($version === '@package_version@' || $version === '@package_branch_alias_version@') { - $io->writeError('You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.'); - } - elseif (Comparator::lessThan($version, '1.0.0')) { - $io->writeError('Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing.'); - exit(1); - } - } - - /** - * Appends content to an existing file. - * - * Polyfill for older versions of Filesystem shipped with Composer phar. - * - * @param string $filename - * The file to which to append content. - * @param string $content - * The content to append. - * - * @throws \Symfony\Component\Filesystem\Exception\IOException - * If the file is not writable. - */ - protected static function appendToFile($filename, $content) { - $fs = new Filesystem(); - - $dir = \dirname($filename); - - if (!is_dir($dir)) { - $fs->mkdir($dir); - } - - if (!is_writable($dir)) { - throw new \Exception(sprintf('Unable to write to the "%s" directory.', $dir), 0, NULL, $dir); - } - - if (FALSE === @file_put_contents($filename, $content, FILE_APPEND)) { - throw new \Exception(sprintf('Failed to write file "%s".', $filename), 0, NULL, $filename); - } - } - -}