Skip to content
Snippets Groups Projects
Select Git revision
  • 2fe55b8f97c63cd2b25428528aabeb136cfd1319
  • main default protected
  • revert-ffead0bd
  • feature/init
  • 1.1.8
  • 1.1.7
  • 1.1.6
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.2
  • 1.1.1
  • 1.1.0
  • 1.0.2
  • 1.0.2-beta3
  • 1.0.2-beta2
  • 1.0.2-beta1
  • 1.0.1
  • 1.0.1-beta4
  • 1.0.1-beta3
  • 1.0.1-beta2
  • 1.0.1-beta1
  • 1.0.0
  • 1.0.0-beta6
24 results

PrepareActivationReminderCommand.php

Blame
  • PrepareActivationReminderCommand.php 6.13 KiB
    <?php
    
    namespace WPDesk\ActivationReminder\Composer;
    
    use Composer\Command\BaseCommand;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    
    /**
     * Can prepare activation reminder for plugin.
     *
     * @package WPDesk\Composer\GitPlugin\Command
     */
    class PrepareActivationReminderCommand extends BaseCommand
    {
    
        protected function configure()
        {
            $this
                ->setName('prepare-activation-reminder')
                ->setDescription('Prepares activation reminder for WP Desk plugin.')
                ->addOption( 'no-dev' );
        }
    
        /**
         * Execute command.
         *
         * @param InputInterface $input
         * @param OutputInterface $output
         * @return int|void|null
         */
        protected function execute(InputInterface $input, OutputInterface $output)
        {
    	    $output->writeln("Creating activation reminder.");
    
    	    $settings = Settings::create_from_composer_settings( $this->getComposer()->getPackage()->getExtra() );
    
    	    $classLoader = require( 'vendor/autoload.php' );
    	    $class_map = $classLoader->getClassMap();
    
    	    $random_class = $this->get_random_class( $class_map );
    	    $random_letter = strtolower( chr( rand( 65, 90 ) ) );
    
    	    $target_file = $this->create_or_get_target_file_name( $class_map, $random_class, $random_letter );
    
    	    if ( ! file_exists( $target_file ) ) {
    		    $target_dir = dirname( $target_file );
    		    $output->writeln( "Target file name: $target_file" );
    		    copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/src/Reminder.php', $target_file );
    		    $popup_javascript_file = $target_dir . '/popup.js';
    		    $popup_css_file        = $target_dir . '/popup.css';
    		    copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/assets/js/popup.js', $popup_javascript_file );
    		    copy( 'vendor/wpdesk/wp-wpdesk-activation-reminder/assets/css/popup.css', $popup_css_file );
    		    $this->prepare_class( $random_class . $random_letter, $target_file, $popup_javascript_file, $popup_css_file, $settings );
    	    }
    
    	    $this->regenerate_autoload( $target_file, $input );
    
    	    $output->writeln( "Activation reminder created." );
    
    		return Command::SUCCESS;
        }
    
        private function create_or_get_target_file_name( array $class_map, $random_class, $random_letter ) {
        	$target_file_store = 'vendor/wpdesk/wp-wpdesk-activation-reminder/target-file';
        	if ( ! file_exists( $target_file_store ) ) {
    		    $target_file = $class_map[ $random_class ];
    		    $target_file = str_replace( '.php', $random_letter . '.php', $target_file );