AutoUpgrade.php
1 month ago
IncludeAutoUpgrade.php
3 years ago
InstallerPlugins.php
1 month ago
class-otgs-installer-upgrade-response.php
1 month ago
InstallerPlugins.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace OTGS\Installer\Upgrade; |
| 4 | |
| 5 | class InstallerPlugins { |
| 6 | |
| 7 | private $installer; |
| 8 | |
| 9 | private $installerPluginFinder; |
| 10 | |
| 11 | private $_filteredInstallerPlugins; |
| 12 | |
| 13 | public function __construct( \WP_Installer $installer, \OTGS_Installer_Plugin_Finder $installerPluginsFinder ) { |
| 14 | $this->installer = $installer; |
| 15 | $this->installerPluginFinder = $installerPluginsFinder; |
| 16 | } |
| 17 | |
| 18 | public function getFilteredInstallerPlugins() { |
| 19 | return $this->filteredInstallerPlugins(); |
| 20 | } |
| 21 | |
| 22 | private function filteredInstallerPlugins() { |
| 23 | if ( null === $this->_filteredInstallerPlugins ) { |
| 24 | $this->_filteredInstallerPlugins = $this->filterInstallerPlugins(); |
| 25 | } |
| 26 | return $this->_filteredInstallerPlugins; |
| 27 | } |
| 28 | |
| 29 | private function filterInstallerPlugins() { |
| 30 | $filteredInstallerPlugins = []; |
| 31 | $installerPluginsFinder = $this->installerPluginFinder; |
| 32 | |
| 33 | foreach ( $installerPluginsFinder->get_otgs_installed_plugins_by_repository() as $repositoryId => $installedRepositoryPlugins ) { |
| 34 | foreach ( $installedRepositoryPlugins as $installedRepositoryPlugin ) { |
| 35 | $pluginObj = $installerPluginsFinder->get_plugin( $installedRepositoryPlugin['slug'], $repositoryId ); |
| 36 | if ( !$pluginObj || $pluginObj->get_external_repo() && $this->installer->plugin_is_registered( $pluginObj->get_external_repo(), $installedRepositoryPlugin['slug'] ) ) { |
| 37 | continue; |
| 38 | } |
| 39 | |
| 40 | $filteredInstallerPlugins[ $repositoryId ][] = $installedRepositoryPlugin; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return $filteredInstallerPlugins; |
| 45 | } |
| 46 | |
| 47 | public function getPluginData( $repositoryId, $pluginId ) { |
| 48 | return current( array_filter( $this->filteredInstallerPlugins()[ $repositoryId ], function ( $plugin ) use ( $pluginId ) { |
| 49 | return $plugin['id'] === $pluginId; |
| 50 | } ) ); |
| 51 | } |
| 52 | } |
| 53 |