Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
<?php
/**
 * Created by PhpStorm.
 * User: danilo
 * Date: 18/12/15
 * Time: 10:58
 */
namespace Modules\Core\Commands\Installers\Scripts;

use Illuminate\Console\Command;
use Modules\Core\Commands\Installers\SetupScript;

class ModuleEnable implements SetupScript
{
    /**
     * @var array
     */
    public $modules = [
    ];
    /**
     * @var array
     */
    public $default = [
        'Core',
        'Themes',
        'Dashboard',
        //'Menu',
        'Users'
    ];

    public function __construct()
    {
        $this->modules = \Module::all();
        foreach ($this->default as $module) {
            if (($key = array_search($module, $this->modules)) !== false) {
                unset($this->modules[$key]);
            }
        }
        $this->modules = array_values($this->modules);
    }

    /**
     * Fire the install script
     * @param  Command $command
     * @return mixed
     */
    public function fire(Command $command)
    {
        if (count($this->modules) > 0) {
            /** @var array $selected * */
            $command->blockMessage('Modules', 'Select modules for use in the CMS', 'comment');
            $selected = $command->choice('Select modules for enable (select multiples separated by comma)', $this->modules, null, null, true);
            $this->enableSelected($command, $selected);
        }

        $this->enableDefault($command);
    }

    protected function enableSelected(Command $command, $selected)
    {
        $command->info('Enabling selected modules', 'comment');
        foreach ($this->modules as $module) {
            if ($command->option('verbose')) {
                $command->call('module:' . (in_array($module, $selected) ? 'enable' : 'disable'), ['module' => (string)$module]);
                continue;
            }
            $command->callSilent('module:' . (in_array($module, $selected) ? 'enable' : 'disable'), ['module' => (string)$module]);
            $command->info((in_array($module, $selected) ? 'Enable' : 'Disable') . ': ' . $module, 'comment');
        }
    }

    protected function enableDefault(Command $command)
    {
        $command->info('Enabling default modules', 'comment');
        foreach ($this->default as $module) {
            if ($command->option('verbose')) {
                $command->call('module:enable', ['module' => (string)$module]);
                continue;
            }
            $command->callSilent('module:enable', ['module' => (string)$module]);
            $command->info('Enable: ' . $module, 'comment');
        }
    }
}