Activate a WordPress plugin.

@param  \Composer\Installer\PackageEvent  $event
@return void
355498
public function activateWordPressPlugin(PackageEvent $event)
    {
        if (! $this->isWordPressPlugin($this->getPackage($event))) {
            return;
        }
        
        static::$plugin->getInstanceOf(PluginInteractor::class)->activate(
            $event->getComposer(),
            $event->getIO(),
            preg_replace('/^wpackagist-plugin\//', '', $this->getPackageName($event))
        );
    }
979788
public function onPostInstall(Event $event)
    {
        $lockFile = new JsonFile($this->lockFile);
        if ($lockFile->exists()) {
            $this->loadPackages($lockFile);
        } else {
            $this->scanPackages();
        }
        $this->runAction('install');
    }
378977
public static function postPackageInstall(PackageEvent $pEvent)
    {
        if ($pEvent->getOperation() instanceof \Composer\DependencyResolver\Operation\InstallOperation) {
            $packageName = $pEvent->getOperation()->getPackage()->getName();
        } else if ($pEvent->getOperation() instanceof \Composer\DependencyResolver\Operation\UpdateOperation) {
            $packageName = $pEvent->getOperation()->getInitialPackage()->getName();
        } else {
            throw new Exception("Event is not supported.");
        }

        $appPath = realpath('.') . DIRECTORY_SEPARATOR;

        $path = realpath('.'
              . DIRECTORY_SEPARATOR
              . $pEvent->getComposer()->getConfig()->get('vendor-dir')
              . DIRECTORY_SEPARATOR
              . $packageName
              . DIRECTORY_SEPARATOR
              . self::SETUP_DIR
              . DIRECTORY_SEPARATOR
              . self::CLI_FILE
        );

        if ($path and is_readable($path)) {
            $config = require($path);

            if (is_array($config)) {
                foreach ($config as $cmd => $args) {
                    if (! is_array($args)) {
                        continue;
                    } else if (count($args) == count($args, COUNT_RECURSIVE)) {
                        self::_execute($cmd, $args);
                    } else {
                        foreach ($args as $cmdArgs) {
                            self::_execute($cmd, $cmdArgs);
                        }
                    }
                }
            }
        }

        return true;
    }
246444
protected function extractPackage(PackageEvent $event): PackageInterface
    {
        if ($event->getOperation() instanceof UpdateOperation) {
            return $event->getOperation()->getTargetPackage();
        }
        return $event->getOperation()->getPackage();
    }
892457
public function addPlugin(PluginInterface $plugin)
    {
        if ($this->io->isDebug()) {
            $this->io->writeError('Loading plugin '.get_class($plugin));
        }
        $this->plugins[] =  $plugin;
        $plugin->activate($this->composer, $this->io);

        if ($plugin instanceof EventSubscriberInterface) {
            $this->composer->getEventDispatcher()->addSubscriber($plugin);
        }
    }
1039021
protected static function installModule(PackageEvent $event, PackageInterface $module)
    {
        $destDir = self::getModuleDestinationDir($event, $module);

        $fs = new Filesystem();
        $fs->mirror(
            static::getInstallPath($event, $module),
            $destDir
        );
    }
223648
public function checkPackageUpdates(PackageEvent $event)
    {
        $operation = $event->getOperation();
        if ($operation instanceof UpdateOperation) {
            $this->_packageUpdates[$operation->getInitialPackage()->getName()] = [
                'from' => $operation->getInitialPackage()->getVersion(),
                'fromPretty' => $operation->getInitialPackage()->getPrettyVersion(),
                'to' => $operation->getTargetPackage()->getVersion(),
                'toPretty' => $operation->getTargetPackage()->getPrettyVersion(),
                'direction' => $event->getPolicy()->versionCompare(
                    $operation->getInitialPackage(),
                    $operation->getTargetPackage(),
                    '<'
                ) ? 'up' : 'down',
            ];
        }
    }
1337697
public static function execute(Event $event) {
    $io = $event->getIO();

    // Search upwards for a composer.json which depends on acquia/lightning.
    $io->write('Searching for root package...');

    $file = static::getRootPackage();

    $package = $file->read();

    // Add the Asset Packagist repository if it does not already exist.
    if (isset($package['repositories'])) {
      $repository_key = NULL;

      foreach ($package['repositories'] as $key => $repository) {
        if ($repository['type'] == 'composer' && strpos($repository['url'], 'https://asset-packagist.org') === 0) {
          $repository_key = $key;
          break;
        }
      }

      if (is_null($repository_key)) {
        $package['repositories']['asset-packagist'] = [
          'type' => 'composer',
          'url' => 'https://asset-packagist.org',
        ];
      }
    }

    // oomphinc/composer-installers-extender is required by Lightning and
    // depends on composer/installers, so it does not need to be specifically
    // included.
    unset(
      $package['require']['composer/installers'],
      $package['require']['oomphinc/composer-installers-extender']
    );

    $package['extra']['installer-types'][] = 'bower-asset';
    $package['extra']['installer-types'][] = 'npm-asset';
    $package['extra']['installer-paths']['docroot/libraries/{$name}'][] = 'type:bower-asset';
    $package['extra']['installer-paths']['docroot/libraries/{$name}'][] = 'type:npm-asset';

    $file->write($package);
    $io->write('Successfully updated your root composer.json file. Switch back to your project root and run "composer update".');
  }
242646
public static function postPackageUpdateAndInstall(PackageEvent $event)
    {
        $operation = $event->getOperation();
        if (!$operation instanceof InstallOperation && !$operation instanceof UpdateOperation) {
            throw new Exception\UnexpectedOperationException('Handling of operation with type "' . $operation->getJobType() . '" not supported', 1348750840);
        }
        $package = ($operation->getJobType() === 'install') ? $operation->getPackage() : $operation->getTargetPackage();
        $packageExtraConfig = $package->getExtra();
        $installPath = $event->getComposer()->getInstallationManager()->getInstallPath($package);

        $evaluatedInstallerResources = false;
        if (isset($packageExtraConfig['neos']['installer-resource-folders'])) {
            foreach ($packageExtraConfig['neos']['installer-resource-folders'] as $installerResourceDirectory) {
                static::copyDistributionFiles($installPath . $installerResourceDirectory);
            }
            $evaluatedInstallerResources = true;
        }

        if ($operation->getJobType() === 'install') {
            if (isset($packageExtraConfig['typo3/flow']['post-install'])) {
                self::runPackageScripts($packageExtraConfig['typo3/flow']['post-install']);
            }
            if (isset($packageExtraConfig['neos/flow']['post-install'])) {
                self::runPackageScripts($packageExtraConfig['neos/flow']['post-install']);
            }
        }

        if ($operation->getJobType() === 'update') {
            if (isset($packageExtraConfig['typo3/flow']['post-update'])) {
                self::runPackageScripts($packageExtraConfig['typo3/flow']['post-update']);
            }
            if (isset($packageExtraConfig['neos/flow']['post-update'])) {
                self::runPackageScripts($packageExtraConfig['neos/flow']['post-update']);
            }
        }

        // TODO: Deprecated from Flow 3.1 remove three versions after.
        if (!$evaluatedInstallerResources && isset($packageExtraConfig['typo3/flow']['manage-resources']) && $packageExtraConfig['typo3/flow']['manage-resources'] === true) {
            static::copyDistributionFiles($installPath . 'Resources/Private/Installer/');
        }
    }
402010
public function removeModuleFiles(PackageEvent $event): void
    {
        $package = $this->extractPackage($event);
        $this->packagePath = $this->vendorPath .DS. $package->getName();
        if ($package->getType() === 'bluz-module' && file_exists($this->packagePath)) {
            if ($package->getExtra() && isset($package->getExtra()['copy-files'])) {
                $this->removeExtras($package->getExtra()['copy-files']);
            }
            $this->removeModule();
        }
    }
244739
public static function packageInRouting(PackageEvent $event)
    {
        self::addJobByOperationType(
            $event->getOperation(),
            function ($package) {
                return new AddRouting($package);
            },
            function ($package) {
                return new RemoveRouting($package);
            }
        );
    }
1290609
public static function postPackageUpdate(PackageEvent $event){
		$installedPackage = $event->getOperation()->getTargetPackage()->getName();
		if (self::checkConfig($event, $installedPackage)) {
			self::phinxMigrateFromPackageName($event, $installedPackage);
		} else {
			die();
		}
	}
162953
public static function execute(Event $event) {
    $io = $event->getIO();

    // Search upwards for a composer.json which depends on Open Social.
    $io->write('Searching for root package...');

    $file = static::getRootPackage();

    $package = $file->read();

    // Add the Asset Packagist repository if it does not already exist.
    if (isset($package['repositories'])) {
      $repository_key = NULL;

      foreach ($package['repositories'] as $key => $repository) {
        if ($repository['type'] == 'composer' && strpos($repository['url'], 'https://asset-packagist.org') === 0) {
          $repository_key = $key;
          break;
        }
      }

      if (is_null($repository_key)) {
        $package['repositories'][] = [
          'type' => 'composer',
          'url' => 'https://asset-packagist.org',
        ];
      }
    }

    // oomphinc/composer-installers-extender is required by Open Social and
    // depends on composer/installers, so it does not need to be specifically
    // included.
    unset(
      $package['require']['oomphinc/composer-installers-extender']
    );

    // Check if we need to add the bower and npm assets to the installer types.
    if (!isset($package['extra']['installer-types']) || !in_array('bower-asset', $package['extra']['installer-types'])) {
      $package['extra']['installer-types'][] = 'bower-asset';
    }
    if (!in_array('npm-asset', $package['extra']['installer-types'])) {
      $package['extra']['installer-types'][] = 'npm-asset';
    }

    // Get root folder based on the location of Drupal core. If we do it in this
    // way we can also support projects that have
    //    $package['extra']['installer-paths']['']
    $root_path = 'html/';
    foreach ($package['extra']['installer-paths'] as $path => $install_type) {
      if (in_array('drupal/core', $install_type, TRUE)) {
        // If Drupal core is installed in the root path we also want the
        // libraries there.
        if ($path == 'core') {
          $root_path = '';
        }
        else {
          $parts = explode('/core', $path);
          if (!empty($parts)) {
            $root_path = $parts[0] . '/';
          }
        }

        break;
      }
    }

    // Add the different library types to the installer paths.
    $package['extra']['installer-paths'][$root_path . 'libraries/{$name}'][] = 'type:drupal-library';
    $package['extra']['installer-paths'][$root_path . 'libraries/{$name}'][] = 'type:bower-asset';
    $package['extra']['installer-paths'][$root_path . 'libraries/{$name}'][] = 'type:npm-asset';

    $file->write($package);
    $io->write('Successfully updated your root composer.json file.');
  }
406247
function _activate_plugin_event_hook() {
            $this->_logger->entrance( 'slug = ' . $this->_slug );

            if ( ! $this->is_user_admin() ) {
                return;
            }

            $this->unregister_uninstall_hook();

            // Clear API cache on activation.
            FS_Api::clear_cache();

            $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );

            $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );

            // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
            // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
            $other_version_basename = $is_premium_version_activation ?
                $this->_free_plugin_basename :
                $this->premium_plugin_basename();

            if ( ! $this->_is_network_active ) {
                /**
                 * During the activation, the plugin isn't yet active, therefore,
                 * _is_network_active will be set to false even if it's a network level
                 * activation. So we need to fix that by looking at the is_network_admin() value.
                 *
                 * @author Vova Feldman
                 */
                $this->_is_network_active = (
                    $this->_is_multisite_integrated &&
                    // Themes are always network activated, but the ACTUAL activation is per site.
                    $this->is_plugin() &&
                    fs_is_network_admin()
                );
            }

            /**
             * If the other module version is activate, deactivate it.
             *
             * is_plugin_active() checks if the plugin active on the site or the network level
             * and deactivate_plugins() deactivates the plugin whether its activated on the site
             * or network level.
             *
             * @author Leo Fajardo (@leorw)
             * @since  1.2.2
             */
            if ( is_plugin_active( $other_version_basename ) ) {
                deactivate_plugins( $other_version_basename );
            }

            if ( $this->is_registered() ) {
                if ( $is_premium_version_activation ) {
                    $this->reconnect_locally();
                }


                // Schedule re-activation event and sync.
//				$this->sync_install( array(), true );
                $this->schedule_install_sync();

                // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
                if ( $is_premium_version_activation ) {
                    $this->_admin_notices->add(
                        sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
                        $this->get_text_x_inline( 'W00t',
                            'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
                    );
                }
            } else if ( $this->is_anonymous() ) {
                if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
                    $plugin_version = $this->_storage->is_anonymous_ms['version'];
                    $network        = true;
                } else {
                    $plugin_version = $this->_storage->is_anonymous['version'];
                    $network        = false;
                }

                /**
                 * Reset "skipped" click cache on the following:
                 *  1. Freemius DEV mode.
                 *  2. WordPress DEBUG mode.
                 *  3. If a plugin and the user skipped the exact same version before.
                 *
                 * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
                 *
                 * @todo  4. If explicitly asked to retry after every activation.
                 */
                if ( WP_FS__DEV_MODE ||
                     (
                         ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
                         $this->get_plugin_version() == $plugin_version
                     )
                ) {
                    $this->reset_anonymous_mode( $network );
                }
            }

            if (
                $is_premium_version_activation &&
                (
                    ( ! $this->is_registered() && $this->is_anonymous() ) ||
                    (
                        $this->is_registered() &&
                        ! $this->is_trial() &&
                        ! $this->has_features_enabled_license()
                    )
                )
            ) {
                $this->_storage->require_license_activation = true;
            }

            if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
                /**
                 * If no previous version of plugin's version exist, it means that it's either
                 * the first time that the plugin installed on the site, or the plugin was installed
                 * before but didn't have Freemius integrated.
                 *
                 * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
                 * on manual activation via the dashboard, is_plugin_activation() is TRUE
                 * only after immediate activation.
                 *
                 * @since 1.1.4
                 * @link  https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
                 */
                $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
            }

            if ( ! $this->_anonymous_mode &&
                 $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
                 ! $this->_isAutoInstall
            ) {
                // Store hint that the plugin was just activated to enable auto-redirection to settings.
                set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
            }

            /**
             * Activation hook is executed after the plugin's main file is loaded, therefore,
             * after the plugin was loaded. The logic is located at activate_plugin()
             * ./wp-admin/includes/plugin.php.
             *
             * @author Vova Feldman (@svovaf)
             * @since  1.1.9
             */
            $this->_storage->was_plugin_loaded = true;
        }
60135
public function onPrePackage(PackageEvent $event)
    {
        if ($event->getIO() instanceof BufferIO) {
            $this->logger->debug($event->getIO()->getOutput(), ['event' => 'extensions']);
        }
    }
1225872
public function onInstallReleaseExecuteComposerInstall(InstallReleaseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
    {
        $release = $event->getRelease();
        $host = $release->getWorkspace()->getHost();
        $connection = $this->ensureConnection($host);

        $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Installing Composer dependencies.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));

        $authenticationFile = $release->getPath().'/auth.json';
        if (empty($this->authentication) === false) {
            $connection->putContents($authenticationFile, json_encode($this->authentication));
        }

        $connection->changeWorkingDirectory($host->getPath());
        $result = $connection->executeCommand(sprintf('php composer.phar install --no-interaction --working-dir="%s" --no-dev --no-scripts --optimize-autoloader', $release->getPath()));

        if ($connection->isFile($authenticationFile)) {
            $connection->delete($authenticationFile);
        }

        if ($result->isSuccessful()) {
            $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Installed Composer dependencies.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
            $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, "{separator} Command output:{separator}\n{command.result}{separator}", $eventName, $this, array('command.result' => $result->getOutput(), 'separator' => "\n=================\n")));
        } else {
            throw new TaskCommandExecutionException('Failed installing Composer dependencies.', $result, $this);
        }
    }
484900
protected function activatePlugin(string $plugin): void
    {
        require_once WPMU_PLUGIN_DIR.'/'.$plugin;

        do_action('activate_'.$plugin);

        $plugins = $this->getActivePlugins();
        $plugins[] = $plugin;

        $this->setActivePlugins($plugins);
    }