From d6fb8986ed61d1cf5c80ae8c5953859975c36ebd Mon Sep 17 00:00:00 2001 From: Sarah Mount Date: Mon, 18 Sep 2023 08:38:19 +0100 Subject: [PATCH] Remove migration commands The last repository with a plugins.json file was migrated recently, and so this code can now be removed. Fixes #141 --- CHANGELOG.md | 3 + generators/migration/generate.php | 519 ------------------- generators/migration/share/available-plugins | 161 ------ src/Dependencies/Migration.php | 157 ------ src/Modules/Dependencies.php | 8 - src/Modules/Plugin.php | 3 - src/Whippet.php | 16 - tests/dependencies/migration_test.php | 192 ------- 8 files changed, 3 insertions(+), 1056 deletions(-) delete mode 100644 generators/migration/generate.php delete mode 100644 generators/migration/share/available-plugins delete mode 100644 src/Dependencies/Migration.php delete mode 100644 tests/dependencies/migration_test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c8a3a02..5bb65484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Support for PHP 8 +### Removed +- `whippet migrate` commands. + ## [2.3.0] - 2023-06-14 ### Added - `whippet deps describe` command, that provides a JSON report on the version tags associated with the commit hashes in `whippet.lock` diff --git a/generators/migration/generate.php b/generators/migration/generate.php deleted file mode 100644 index 1f59daff..00000000 --- a/generators/migration/generate.php +++ /dev/null @@ -1,519 +0,0 @@ -options = $options; - $this->manual_fixes = array(); - $this->automatic_fixes = array(); - } - - function generate() { - $old = $this->options->old; - $new = $this->options->new; - - if(!file_exists($old)) { - echo "Unable to find directory: {$old}\n"; - } - - if(!file_exists($new)) { - echo "Unable to find directory: {$new}\n"; - } - - // TODO: sanity checks - // Does $old look like a wp-content? - // Does $new look like a whippet app? - // Are they both git repos? - - $git = new \Dxw\Whippet\Git\Git($old); - - - // - // 1. Get a list of all the submodules. Add entries for any that are wordpress-plugins/whatever. - // 2. Copy over all the themes - // 3. Copy over all plugins that aren't submodules - // * Ignore index.php - // * Warn about plugin files that are not in a directory - // * List all plugins copied into the app. - // 4. Ignoring plugins, are there any other submodules? If so, recreated them (in the right place) - // 5. Copy over whippet-wp-config.php, if it exists - // 6. List all files that are not dealt with by the above, and prompt user to deal with them. - // Don't worry about: - // * uploads - // * DS_Store - // * ...? - // 7. Summarise what happened to the plugins. For each: - // * Was it put in Plugins or copied directly? - // * Was it in its own directory? (can we do that automagically?) - // * If it's copied directly, does a similar-looking repo exist? - // * Is there an inspection for the plugin, and if so, what's the result? - // - - // - // Check that all submodules are well formed - // - - echo "Loading submodules\n"; - $submodules = $git->submodule_status(); - - foreach($submodules as $submodule_dir => $submodule) { - if(!empty($submodule->status)) { - echo "Submodule {$submodule->dir} has unmerged changes, is uninitialised, or is not on the index commit. Aborting.\n"; - exit(1); - } - } - - - // - // Fetch all the files, plugins and themes from the old project, and work out which are submoduled - // - - echo "Loading plugins\n"; - - $plugins = $this->get_plugins("{$old}/plugins"); - - echo "Loading themes\n"; - $themes = $this->get_themes("{$old}/themes"); - - echo "Loading everything else\n"; - $other_files = $this->get_rogue_files($old, $plugins, $themes); - - // Find out which ones are submoduled - // No need to worry about themes here, because they're not whippet managed. They're dealt with below. - echo "Looking for Whippet manageable plugins\n"; - foreach($plugins as $plugin_file => $plugin_data) { - foreach($submodules as $submodule_dir => $submodule) { - // If it looks like a theme, make a note of that for later - if(dirname($submodule->dir) == "themes") { - $submodule->theme_dir = basename($submodule->dir); - } - - // From this point on, we only want plugins - if(dirname($submodule->dir) != 'plugins' || dirname($plugin_file) != basename($submodule->dir)) { - continue; - } - - $plugins[$plugin_file]['is_submodule'] = (isset($submodule->remotes['origin']) && preg_match('/^git@git\.dxw\.net:wordpress-plugins\//', $submodule->remotes['origin'])); - - $submodules[$submodule_dir]->plugin_file = $plugin_file; - } - } - - - // - // Add submoduled plugins to Plugins file. Remove those submodule & plugin entries. - // - - // Always start with a fresh file - // Whippet init adds akismet (as it is part of the WP distro) but we only want it now if it's in $old - file_put_contents("{$new}/plugins", "source = \"git@git.govpress.com:wordpress-plugins/\"\n"); - - echo "Updating Plugins file\n"; - foreach($plugins as $plugin_file => $plugin_data) { - if(!isset($plugin_data['is_submodule']) || !$plugin_data['is_submodule']) { - continue; - } - - $plugin_dir = dirname($plugin_file); - - file_put_contents("{$new}/plugins", "{$plugin_dir}=\n", FILE_APPEND); - - unset($plugins[$plugin_file]); - unset($submodules["plugins/{$plugin_dir}"]); - - $this->automatic_fixes[] = "Added plugin {$plugin_dir} to the Plugins file"; - } - - - // - // Check non-Whippet-managed plugins so we can warn if they are on directory or in auto-wordpress - // - - $available_plugins = file(dirname(__FILE__) . "/share/available-plugins"); - - echo "Sanity-checking left over plugins\n"; - - foreach($plugins as $plugin_file => $plugin_data) { - if(array_search(dirname($plugin_file) . "\n", $available_plugins) !== false) { - $this->manual_fixes[] = "Non-whippet-managed plugin is available in git: $plugin_file. Should it be Whippet-managed?"; - } else { - $plugin_slug = dirname($plugin_file); - - if($plugin_slug == '.') { - $plugin_slug = preg_replace("/\.php$/", '', $plugin_file); - } - - $directory_headers = get_headers("http://www.wordpress.org/plugins/{$plugin_slug}/"); - - if(preg_match('/200 OK/', $directory_headers[0])) { - $this->manual_fixes[] = "Non-whippet-managed plugin might be available on the Directory: " . dirname($plugin_file); - } - } - } - - - // - // Re-add submodules that are left-over, and if any are plugins, remove the matching plugin entry - // - - echo "Adding submodules\n"; - foreach($submodules as $dir => $submodule) { - if(count($submodule->remotes['origin']) != 1) { - $this->manual_fixes[] = "Skipped submodule {$submodule->dir}, because it does not have exactly 1 remote. You'll need to manually add the one you want."; - - unset($submodules[$dir]); - continue; - } - - $remote = array_pop($submodule->remotes); - - if(!empty($submodule->theme_dir)) { - if(!$this->is_parent_theme($themes[$submodule->theme_dir]) && array_search($submodule->theme_dir, array("twentyten", "twentyeleven", "twentytwelve", "twentythirteen", "twentyfourteen")) !== false) { - $this->manual_fixes[] = "Refusing to submodule a default theme from {$remote} at wp-content/{$submodule->dir}. Add a submodule for this theme manually if it is required."; - - unset($submodules[$dir]); - unset($themes[$submodule->theme_dir]); - continue; - } - else if($this->is_parent_theme($themes[$submodule->theme_dir])) { - $this->manual_fixes[] = "Submoduled a default theme from {$remote} at wp-content/{$submodule->dir}, because it is a parent of: " . implode(', ', $themes[$submodule->theme_dir]['children']); - } - } - - $git = new \Dxw\Whippet\Git\Git($new); - if(!$git->submodule_add($remote, "wp-content/" . $submodule->dir)) { - // This error will be added to manual fixes later, by seeing if anything is left over in $submodules. - continue; - } - - if(strpos($remote, "git@git.govpress.com") === false) { - $this->manual_fixes[] = "Non-dxw git repo submoduled: {$remote} at {$submodule->dir}"; - } - - if(isset($submodule->plugin_file)) { - unset($plugins[$submodule->plugin_file]); - - $this->automatic_fixes[] = "Submoduled plugin from {$remote} at: wp-content/" . $submodule->dir; - } - else if(isset($submodule->theme_dir)) { - unset($themes[$submodule->theme_dir]); - - $this->automatic_fixes[] = "Submoduled theme from {$remote} at: wp-content/" . $submodule->dir; - } - else { - $this->automatic_fixes[] = "Submodule added at: wp-content/" . $submodule->dir; - } - - unset($submodules[$dir]); - } - - - // - // Copy over any plugins that are left over - // - - echo "Copying project plugins\n"; - foreach($plugins as $plugin_file => $plugin_data) { - if(dirname($plugin_file) != '.') { - $this->recurse_copy("{$old}/plugins/" . dirname($plugin_file), "{$new}/wp-content/plugins/" . dirname($plugin_file)); - - $this->automatic_fixes[] = "Copied plugin directory " . dirname($plugin_file) . " into the project"; - } - else { - $this->recurse_copy("{$old}/plugins/{$plugin_file}", "{$new}/wp-content/plugins"); - - $this->automatic_fixes[] = "Copied plugin file {$plugin_file} into the project"; - } - - unset($plugins[$plugin_file]); - } - - - // - // Copy over any themes that are left over - // - - echo "Copying project themes\n"; - foreach($themes as $theme_dir => $theme_data) { - if(!$this->is_parent_theme($theme_data) && array_search($theme_dir, array("twentyten", "twentyeleven", "twentytwelve", "twentythirteen", "twentyfourteen")) !== false) { - $this->manual_fixes[] = "Refusing to copy a default theme into the project: {$theme_dir}. Copy it manually if you need it."; - - unset($themes[$theme_dir]); - continue; - } - else if($this->is_parent_theme($theme_data)) { - $this->manual_fixes[] = "Copied theme directory {$theme_dir} into the project, because it is a parent of: " . implode(', ', $theme_data['children']); - } - - $new_theme_dir = "{$new}/wp-content/themes/" . dirname($theme_dir); - - if(!file_exists($new_theme_dir)) { - mkdir("{$new_theme_dir}",0755,true); // For themes within subdirs - } - - $this->recurse_copy("{$old}/themes/{$theme_dir}","{$new_theme_dir}/{$theme_dir}"); - - $this->automatic_fixes[] = "Copied theme directory {$theme_dir} into the project"; - - unset($themes[$theme_dir]); - } - - - // - // Check that we don't have any themes, plugins or submodules left over. - // - - echo "Checking for unhandled plugins, themes and submodules\n"; - - // Make sure there's nothing left - foreach($plugins as $plugin_file => $plugin_data) { - $this->manual_fixes[] = "Plugin $plugin_file was not migrated"; - } - - foreach($themes as $theme_dir => $theme_data) { - $this->manual_fixes[] = "Plugin $theme_dir was not migrated"; - } - - foreach($submodules as $submodule_dir => $submodule) { - $this->manual_fixes[] = "Submodule $submodule_dir was not migrated"; - } - - - // - // If there are language files, copy them - // - - if(file_exists("{$old}/languages")) { - echo "Copying language files\n"; - - mkdir("{$new}/wp-content/languages/"); - foreach (glob("{$old}/languages/*.mo") as $file) { - copy($file, "{$new}/wp-content/languages/{$file}"); - } - - $this->automatic_fixes[] = "Copied language directory into the project"; - } - - - // - // What happened? - // - - $results = ""; - - $results .= "\n\nApplied these automatic fixes:\n"; - $results .= "==============================\n"; - - foreach($this->automatic_fixes as $fix) { - $results .= " $fix\n"; - } - - - $results .= "\n\nNotices/possible manual fixes:\n"; - $results .= "==============================\n"; - - if(!count($this->manual_fixes)) { - $results .= " None.\n"; - } - else { - foreach($this->manual_fixes as $fix) { - $results .= " $fix\n"; - } - } - - - $results .= "\n\nLeft-over files:\n"; - $results .= "================\n"; - - if(!count($other_files)) { - $results .= " None.\n"; - } - else { - foreach($other_files as $file) { - $results .= " $file\n"; - } - } - - file_put_contents("{$new}/migration.log", $results); - echo $results; - } - - function is_parent_theme($theme) { - return count($theme['children']) !== 0; - } - - function get_themes($dir) { - $themes = array(); - - foreach(new \DirectoryIterator($dir) as $file) { - if($file->isDot() || !$file->isDir()) continue; - - $got_one = false; - - $styles = "{$dir}/" . $file->getFilename() . "/style.css"; - - if(file_exists($styles)) { - $theme_data = $this->get_file_data($styles); - - if(!empty($theme_data['Theme Name'])) { - $themes[$file->getFilename()] = $theme_data; - $got_one = true; - } - } - else { - foreach(new \DirectoryIterator($file->getPathname()) as $sub_file) { - if($sub_file->isDot() || !$sub_file->isDir()) continue; - - $styles = "{$dir}/" . $file->getFilename() . "/" . $sub_file->getFilename() . "/style.css"; - - if(file_exists($styles)) { - $theme_data = $this->get_file_data($styles); - - if(!empty($theme_data['Theme Name'])) { - $themes[$file->getFilename() . '/' . $sub_file->getFilename()] = $theme_data; - - $got_one = true; - } - } - } - } - - if(!$got_one) { - $this->manual_fixes[] = "Unable to find a theme in " . $file->getPathname() . ". Is there one there?"; - } - } - - foreach($themes as $parent_theme_dir => $parent_theme_data) { - $themes[$parent_theme_dir]['children'] = array(); - - foreach($themes as $theme_dir => $theme_data) { - if($parent_theme_dir == $theme_data['Template']) { - $themes[$parent_theme_dir]['children'][] = $theme_dir; - } - } - } - - return $themes; - } - - function get_plugins($dir) { - $plugins = array(); - - foreach(new \DirectoryIterator($dir) as $file) { - if($file->isDot()) continue; - - if($file->isDir()) { - foreach(new \DirectoryIterator("{$dir}/{$file}") as $sub_file) { - $the_file = "{$file}/" . $sub_file->getFilename(); - $plugin_data = $this->get_file_data("{$dir}/" . $the_file); - - if(!empty($plugin_data['Name'])) { - $plugins[$the_file] = $plugin_data; - } - } - } - else if(preg_match('/\.php$/', $file->getFilename())) { - $the_file = $file->getFilename(); - - $plugin_data = $this->get_file_data("{$dir}/" . $the_file); - - if(!empty($plugin_data['Name'])) { - $plugins[$the_file] = $plugin_data; - } - } - } - - return $plugins; - } - - function get_file_data($plugin_file) { - $all_headers = array( - 'Name' => 'Plugin Name', - 'Theme Name' => 'Theme Name', - 'PluginURI' => 'Plugin URI', - 'Theme URI' => 'Theme URI', - 'Template' => 'Template', - 'Version' => 'Version', - 'Description' => 'Description', - 'Author' => 'Author', - 'AuthorURI' => 'Author URI', - 'TextDomain' => 'Text Domain', - 'DomainPath' => 'Domain Path', - 'Network' => 'Network', - // Site Wide Only is deprecated in favor of Network. - '_sitewide' => 'Site Wide Only', - ); - - $fp = fopen( $plugin_file, 'r' ); - $file_data = fread( $fp, 8192 ); - fclose( $fp ); - - $file_data = str_replace( "\r", "\n", $file_data ); - - foreach ( $all_headers as $field => $regex ) { - if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) { - $plugin_data[ $field ] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1] )); - } - else { - $plugin_data[ $field ] = ''; - } - } - - // Site Wide Only is the old header for Network - if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { - $plugin_data['Network'] = $plugin_data['_sitewide']; - } - - $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ); - unset( $plugin_data['_sitewide'] ); - - $plugin_data['Title'] = $plugin_data['Name']; - $plugin_data['AuthorName'] = $plugin_data['Author']; - - return $plugin_data; - } - - function get_rogue_files($directory, $plugins, $themes) { - $rogue_files = array(); - - $ignore_paths = array( - ".git", - "index.php", - "plugins/index.php", - "themes/index.php" - ); - - foreach($themes as $theme_dir => $theme) { - $ignore_paths[] = "themes/{$theme_dir}"; - } - - foreach($plugins as $plugin_file => $plugin) { - $path = dirname($plugin_file) == '.' ? basename($plugin_file) : dirname($plugin_file); - - $ignore_paths[] = "plugins/" . $path; - } - - foreach($ignore_paths as $k => $path) { - $ignore_paths[$k] = realpath("{$directory}/{$path}"); - } - - $iterator = new \RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); - foreach(new \RecursiveIteratorIterator($iterator) as $filename => $file) { - $match = false; - foreach($ignore_paths as $path) { - if(strpos($file->getRealPath(), $path) === 0) { - $match = true; - break; - } - } - - if(!$match) { - $rogue_files[] = $file->getPathname(); - } - } - - return array_unique($rogue_files); - } - -}; diff --git a/generators/migration/share/available-plugins b/generators/migration/share/available-plugins deleted file mode 100644 index 09154ff2..00000000 --- a/generators/migration/share/available-plugins +++ /dev/null @@ -1,161 +0,0 @@ -1-jquery-photo-gallery-slideshow-flash -achievements -add-local-avatar -advanced-custom-fields -akismet -audit-trail -authors -autochimp -auto-join-groups -addthis -better-anchor-links -better-rss-widget -breadcrumb-navxt -broken-link-checker -bbpress -bp-export-users -bp-external-activity -bp-password-strength -bp-group-hierarchy -bp-group-management -buddypress -buddypress-group-email-subscription -buddypress-profile-progression -buddypress-sitewide-activity-widget -captcha -category-posts -category-specific-rss-feed-menu -comprehensive-twitter-search-plugin -contact-form-7 -cookie-control -csv-to-sorttable -custom-post-widget -custom-post-type-ui -document-repository -dublin-core-for-wp -duplicate-post -efficient-related-posts -events-manager -exclude-pages -extended-categories-widget -disqus-comment-system -easy-embed -eps-301-redirects -featured-content-gallery -flexi-pages-widget -google-analyticator -google-custom-search -google-analytics-dashboard -google-sitemap-generator -growmap-anti-spambot-plugin -iframe -image-widget -in-twitter -invite-anyone -i-recommend-this -jw-player-plugin-for-wordpress -kimili-flash-embed -latest-tweets-widget -mailchimp -more-privacy-options -msmc-redirect-after-comment -my-page-order -network-latest-posts -network-privacy -nextgen-gallery -nice-navigation -notifications-to-all-administrators -opml-importer -page-tagger -page-excerpt -pagely-multiedit -pagemash -photo-galleria -polldaddy -posts-to-posts -post-type-switcher -quick-pagepost-redirect-plugin -quick-flickr-widget -random-image-selector -rating-widget -really-simple-captcha -recently-updated-pages -redirection -regenerate-thumbnails -remove-dashboard-access-for-non-admins -rewrite-rules-inspector -sabre -shareaholic -si-captcha-for-wordpress -si-contact-form -simple-comment-editing -slickr-flickr -slick-social-share-buttons -smart-youtube -snack-bar -spots -subscribe2 -subscribe-to-comments -super-simple-google-analytics -tinymce-advanced -the-events-calendar -trackable-social-share-icons -theme-my-login -total-slider -tubepress -twitter-widget-pro -unconfirmed -underconstruction -unfiltered-mu -user-activation-keys -user-photo -user-switching -visual-form-builder -widget-logic -wordpress-mu-domain-mapping -wordpress-importer -wordpress-seo -wp-crontrol -wp-issuu -wp-page-widget -wp-paginate -wp-photo-album-plus -wp-rss-aggregator -wp-to-twitter -xml-sitemap-feed -yet-another-related-posts-plugin -zigwidgetclass -cms-tree-page-view -relevanssi -after-the-deadline -post-expirator -rss-import -wp-piwik -page-links-to -google-analytics-for-wordpress -twitget -acf-options-page -acf-repeater -bwp-google-xml-sitemaps -social-media-feather -co-authors-plus -chartboot-for-wordpress -acf-flexible-content -citizen-space -unitydog -wp-html-sitemap -wp-realtime-sitemap -advanced-excerpt -wp-pagenavi -mce-table-buttons -sample-slider -cpt-bootstrap-carousel -multisite-user-management -wp-ramp-postid-meta-translation -wordpress-form-manager -wp-user-avatar -fourteen-colors -decent-comments -enable-media-replace -syntaxhighlighter -capability-manager-enhanced diff --git a/src/Dependencies/Migration.php b/src/Dependencies/Migration.php deleted file mode 100644 index ab7b8298..00000000 --- a/src/Dependencies/Migration.php +++ /dev/null @@ -1,157 +0,0 @@ -factory = $factory; - $this->dir = $dir; - } - - public function migrate() - { - $result = $this->loadFiles(); - if ($result->isErr()) { - return $result; - } - - $whippetData = [ - 'src' => [ - 'plugins' => $this->pluginsFile['source'], - ], - 'plugins' => [ - ], - ]; - - foreach ($this->pluginsFile['plugins'] as $name => $data) { - $whippetData['plugins'][] = $this->getPlugin($name, $data); - } - - $whippetJson = $this->factory->newInstance('\\Dxw\\Whippet\\Files\\WhippetJson', $whippetData); - $whippetJson->saveToPath($this->dir.'/whippet.json'); - - return \Result\Result::ok(); - } - - private function loadFiles() - { - if (is_file($this->dir.'/whippet.json')) { - return \Result\Result::err('will not overwrite existing whippet.json'); - } - - if (!is_file($this->dir.'/plugins')) { - return \Result\Result::err('plugins file not found in current working directory'); - } - - $result = $this->parsePluginsFile(file_get_contents($this->dir.'/plugins')); - if ($result->isErr()) { - return $result; - } - $this->pluginsFile = $result->unwrap(); - - return \Result\Result::ok(); - } - - private function getPlugin($name, $data) - { - $newPlugin = [ - 'name' => $name, - ]; - - if ($data->revision !== 'master') { - $newPlugin['ref'] = $data->revision; - } - - if ($data->repository !== '') { - $newPlugin['src'] = $data->repository; - } - - return $newPlugin; - } - - // Copied/pasted from ManifestIo because that class doesn't expose the source line - // - // Beware of untested code - private function parsePluginsFile($raw_file) - { - // Check for #-comments - $lines = explode("\n", $raw_file); - foreach ($lines as $line) { - if (preg_match('/^\s*#/', $line)) { - return \Result\Result::err('Comments beginning with # are not permitted'); - } - } - - $plugins = parse_ini_string($raw_file); - - if (!is_array($plugins)) { - return \Result\Result::err('Unable to parse Plugins file'); - } - - // Got plugins - turn names to sources - $source = $append = ''; - $plugins_manifest = new \stdClass(); - - foreach ($plugins as $plugin => $data) { - // - // Special lines - // - - if ($plugin == 'source') { - if (empty($data)) { - return \Result\Result::err("Source is empty. It should just specify a repo root:\n\n source = 'git@git.govpress.com:wordpress-plugins/'\n\nWhippet will attempt to find a source for your plugins by appending the plugin name to this URL."); - } - - $source = $data; - continue; - } - - if ($plugin == 'append') { - $append = $data; - continue; - } - - $repository = $revision = ''; - - // - // Everything else should be a plugin - // - - // First see if there is data. - if (!empty($data)) { - // Format: LABEL[, REPO] - if (strpos($data, ',') !== false) { - list($revision, $repository) = explode(',', $data); - } else { - $revision = $data; - } - } - - // if (empty($repository)) { - // $repository = "{$source}{$plugin}{$append}"; - // } - - if (empty($revision)) { - $revision = 'master'; - } - - // We should now have repo and revision - $plugins_manifest->$plugin = new \stdClass(); - $plugins_manifest->$plugin->repository = $repository; - $plugins_manifest->$plugin->revision = $revision; - } - - return \Result\Result::ok([ - 'source' => $source, - 'plugins' => $plugins_manifest, - ]); - } -} diff --git a/src/Modules/Dependencies.php b/src/Modules/Dependencies.php index fffc7ed8..02a3329c 100644 --- a/src/Modules/Dependencies.php +++ b/src/Modules/Dependencies.php @@ -32,7 +32,6 @@ public function commands() }; $this->command('install', 'Installs dependencies', $inspections_host_option); $this->command('update', 'Updates dependencies to their latest versions. Use deps update [type]/[name] to update a specific dependency', $inspections_host_option); - $this->command('migrate', 'Converts legacy plugins file to whippet.json'); $this->command('validate', 'Validate whippet.json and whippet.lock files'); $this->command('describe', 'List dependencies and their versions'); } @@ -75,13 +74,6 @@ public function update($dep = null) } } - public function migrate() - { - $dir = new \Dxw\Whippet\ProjectDirectory(getcwd()); - $migration = new \Dxw\Whippet\Dependencies\Migration($this->factory, $dir); - $this->exitIfError($migration->migrate()); - } - public function validate() { $dir = $this->getDirectory(); diff --git a/src/Modules/Plugin.php b/src/Modules/Plugin.php index 8a548a74..1d85bad0 100644 --- a/src/Modules/Plugin.php +++ b/src/Modules/Plugin.php @@ -26,9 +26,6 @@ private function deprecationNotice($internal) $this->warningText([ 'The plugins subcommand is deprecated and will be removed in a future release.', '', - 'To migrate a `plugins` file to a `whippet.json` file, run the following:', - ' $ whippet deps migrate', - '', 'Once you have a `whippet.json` file, you can run the following instead of `whippet plugins upgrade`:', ' $ whippet deps update', '', diff --git a/src/Whippet.php b/src/Whippet.php index f2b1e6de..bbbab69f 100644 --- a/src/Whippet.php +++ b/src/Whippet.php @@ -25,10 +25,6 @@ public function commands() $this->command('init [PATH]', 'Creates a new Whippet application at PATH. NB: this is a shortcut for whippet generate -d PATH whippet.', function ($option_parser) { $option_parser->addRule('r|repository::', 'Override the default application.json WordPress repository with this one'); }); - - $this->command('migrate OLDPATH NEWPATH', 'Examines an existing wp-content directory and attempts to create an identical Whippet application.'); - $this->command('dependencies SUBCOMMAND', 'Manage dependencies (themes, plugins)'); - $this->command('deps SUBCOMMAND', 'Alias for dependencies'); } public function plugins($plugin_command) @@ -72,18 +68,6 @@ public function generate($thing = false) (new Modules\Generate())->start($thing, $this->options); } - // TODO: This should just be a generator like any other, but it's currently hard to do one - // command with several different combinations of required arguments. So just a separate - // command for now. - public function migrate($old, $new) - { - $this->options = new \stdClass(); - $this->options->old = $old; - $this->options->new = $new; - - (new Modules\Generate())->start('migration', $this->options); - } - public function dependencies() { (new Modules\Dependencies())->start(array_slice($this->argv, 1)); diff --git a/tests/dependencies/migration_test.php b/tests/dependencies/migration_test.php deleted file mode 100644 index 8b79eab4..00000000 --- a/tests/dependencies/migration_test.php +++ /dev/null @@ -1,192 +0,0 @@ -getMockBuilder('\\Dxw\\Whippet\\Files\\WhippetJson') - ->disableOriginalConstructor() - ->getMock(); - - $whippetJson->expects($this->exactly(1)) - ->method('saveToPath') - ->with($path); - - return $whippetJson; - } - - public function testMigrate() - { - $dir = $this->getDir(); - - file_put_contents($dir.'/plugins', implode("\n", [ - 'source = "git@git.govpress.com:wordpress-plugins/"', - 'twitget=', - 'acf-options-page=', - 'new-members-only=', - 'wordpress-importer=', - 'page-links-to=', - 'akismet=', - 'acf-repeater=', - 'advanced-custom-fields=', - 'theme-my-login=', - 'breadcrumb-navxt=', - 'contact-form-7=', - 'wp-realtime-sitemap=', - 'tinymce-advanced=', - 'relevanssi-premium=', - 'jw-player-plugin-for-wordpress=', - 'gravityforms=', - 'unconfirmed=', - 'oauth2-server = ,git@git.govpress.com:dxw-wp-plugins/oauth2-server', - 'network-approve-users = v1.1.1,git@git.govpress.com:dxw-wp-plugins/network-approve-users', - ])); - - $whippetJson = $this->getWhippetJsonExpectSavePath($dir.'/whippet.json'); - - $this->addFactoryNewInstance('\\Dxw\\Whippet\\Files\\WhippetJson', [ - 'src' => [ - 'plugins' => 'git@git.govpress.com:wordpress-plugins/', - ], - 'plugins' => [ - ['name' => 'twitget'], - ['name' => 'acf-options-page'], - ['name' => 'new-members-only'], - ['name' => 'wordpress-importer'], - ['name' => 'page-links-to'], - ['name' => 'akismet'], - ['name' => 'acf-repeater'], - ['name' => 'advanced-custom-fields'], - ['name' => 'theme-my-login'], - ['name' => 'breadcrumb-navxt'], - ['name' => 'contact-form-7'], - ['name' => 'wp-realtime-sitemap'], - ['name' => 'tinymce-advanced'], - ['name' => 'relevanssi-premium'], - ['name' => 'jw-player-plugin-for-wordpress'], - ['name' => 'gravityforms'], - ['name' => 'unconfirmed'], - [ - 'name' => 'oauth2-server', - 'src' => 'git@git.govpress.com:dxw-wp-plugins/oauth2-server', - ], - [ - 'name' => 'network-approve-users', - 'ref' => 'v1.1.1', - 'src' => 'git@git.govpress.com:dxw-wp-plugins/network-approve-users', - ], - ], - ], $whippetJson); - - $this->addFactoryCallStatic('\\Dxw\\Whippet\\Git\\Git', 'ls_remote', 'git@git.govpress.com:wordpress-themes/my-theme', 'v1.4', \Result\Result::ok('27ba906')); - $this->addFactoryCallStatic('\\Dxw\\Whippet\\Git\\Git', 'ls_remote', 'git@git.govpress.com:wordpress-plugins/my-plugin', 'v1.6', \Result\Result::ok('d961c3d')); - - $migration = new \Dxw\Whippet\Dependencies\Migration( - $this->getFactory(), - $this->getProjectDirectory($dir) - ); - - ob_start(); - $result = $migration->migrate(); - $output = ob_get_clean(); - - $this->assertFalse($result->isErr()); - $this->assertEquals('', $output); - } - - public function testMigrateDeprecatedComment() - { - $dir = $this->getDir(); - - file_put_contents($dir.'/plugins', implode("\n", [ - '#bad comment', - 'source = "git@git.govpress.com:wordpress-plugins/"', - 'twitget=', - ])); - - $migration = new \Dxw\Whippet\Dependencies\Migration( - $this->getFactory(), - $this->getProjectDirectory($dir) - ); - - ob_start(); - $result = $migration->migrate(); - $output = ob_get_clean(); - - $this->assertTrue($result->isErr()); - $this->assertEquals('Comments beginning with # are not permitted', $result->getErr()); - $this->assertEquals('', $output); - - $this->assertFalse(file_exists($dir.'/whippet.json')); - } - - public function testMigrateMissingSource() - { - $dir = $this->getDir(); - - file_put_contents($dir.'/plugins', implode("\n", [ - 'source=', - ])); - - $migration = new \Dxw\Whippet\Dependencies\Migration( - $this->getFactory(), - $this->getProjectDirectory($dir) - ); - - ob_start(); - $result = $migration->migrate(); - $output = ob_get_clean(); - - $this->assertTrue($result->isErr()); - $this->assertEquals("Source is empty. It should just specify a repo root:\n\n source = 'git@git.govpress.com:wordpress-plugins/'\n\nWhippet will attempt to find a source for your plugins by appending the plugin name to this URL.", $result->getErr()); - $this->assertEquals('', $output); - - $this->assertFalse(file_exists($dir.'/whippet.json')); - } - - public function testMigrateMissingPluginsFile() - { - $dir = $this->getDir(); - - $migration = new \Dxw\Whippet\Dependencies\Migration( - $this->getFactory(), - $this->getProjectDirectory($dir) - ); - - ob_start(); - $result = $migration->migrate(); - $output = ob_get_clean(); - - $this->assertTrue($result->isErr()); - $this->assertEquals('plugins file not found in current working directory', $result->getErr()); - $this->assertEquals('', $output); - - $this->assertFalse(file_exists($dir.'/whippet.json')); - } - - public function testMigratePreExistingWhippetJson() - { - $dir = $this->getDir(); - touch($dir.'/whippet.json'); - - file_put_contents($dir.'/plugins', implode("\n", [ - 'source = "git@git.govpress.com:wordpress-plugins/"', - 'twitget=', - ])); - - $migration = new \Dxw\Whippet\Dependencies\Migration( - $this->getFactory(), - $this->getProjectDirectory($dir) - ); - - ob_start(); - $result = $migration->migrate(); - $output = ob_get_clean(); - - $this->assertTrue($result->isErr()); - $this->assertEquals('will not overwrite existing whippet.json', $result->getErr()); - $this->assertEquals('', $output); - } -}