diff --git a/app/Http/Controllers/Common/SettingsController.php b/app/Http/Controllers/Common/SettingsController.php index e2b863062..9a905c2e6 100644 --- a/app/Http/Controllers/Common/SettingsController.php +++ b/app/Http/Controllers/Common/SettingsController.php @@ -406,18 +406,6 @@ class SettingsController extends Controller */ $faveoconfig = config_path().DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$filename.'.php'; if ($faveoconfig) { - - //copy($config, $faveoconfig); - /* - * write provider list in app.php line 128 - */ - $app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php'; - chmod($app, 0644); - $str = "\n\n\t\t\t'App\\Plugins\\$filename"."\\ServiceProvider',"; - $line_i_am_looking_for = 190; - $lines = file($app, FILE_IGNORE_NEW_LINES); - $lines[$line_i_am_looking_for] = $str; - file_put_contents($app, implode("\n", $lines)); $plug->create(['name' => $filename, 'path' => $filename, 'status' => 1]); return redirect()->back()->with('success', Lang::get('lang.plugin-installed')); @@ -584,12 +572,6 @@ class SettingsController extends Controller $plugs = new Plugin(); $plug = $plugs->where('name', $slug)->first(); if (!$plug) { - $app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php'; - $str = "\n'App\\Plugins\\$slug"."\\ServiceProvider',"; - $line_i_am_looking_for = 190; - $lines = file($app, FILE_IGNORE_NEW_LINES); - $lines[$line_i_am_looking_for] = $str; - file_put_contents($app, implode("\n", $lines)); $plugs->create(['name' => $slug, 'path' => $slug, 'status' => 1]); return redirect()->back()->with('success', 'Status has changed'); @@ -597,25 +579,9 @@ class SettingsController extends Controller $status = $plug->status; if ($status == 0) { $plug->status = 1; - - $app = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php'; - $str = "\n 'App\\Plugins\\$slug"."\\ServiceProvider',"; - $line_i_am_looking_for = 190; - $lines = file($app, FILE_IGNORE_NEW_LINES); - $lines[$line_i_am_looking_for] = $str; - file_put_contents($app, implode("\n", $lines)); } if ($status == 1) { $plug->status = 0; - /* - * remove service provider from app.php - */ - $str = "\n'App\\Plugins\\$slug"."\\ServiceProvider',"; - $path_to_file = base_path().DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.php'; - - $file_contents = file_get_contents($path_to_file); - $file_contents = str_replace($str, '//', $file_contents); - file_put_contents($path_to_file, $file_contents); } $plug->save(); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 24f9e7b4f..44e5c1cf9 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Model\Update\BarNotification; +use App\Model\helpdesk\Settings\Plugin; use Illuminate\Queue\Events\JobFailed; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; @@ -28,9 +29,9 @@ class AppServiceProvider extends ServiceProvider if ($this->app->environment('local', 'testing')) { $this->app->register(DuskServiceProvider::class); } - // if (isInstall()) { - // $this->plugin(); - // } + if (isInstall()) { + $this->registerPlugin(); + } } public function boot() @@ -53,49 +54,14 @@ class AppServiceProvider extends ServiceProvider }); } - public function plugin() + public function registerPlugin() { - if (isPlugin('Ldap') && $this->isPluginDir('Ldap')) { - $this->app->register(\App\Plugins\Ldap\ServiceProvider::class); - } - if (isPlugin('Chat') && $this->isPluginDir('Chat')) { - $this->app->register(\App\Plugins\Chat\ServiceProvider::class); - } - if (isPlugin('Envato') && $this->isPluginDir('Envato')) { - $this->app->register(\App\Plugins\Envato\ServiceProvider::class); - } - if (isPlugin('Htrunk') && $this->isPluginDir('Htrunk')) { - $this->app->register(\App\Plugins\Htrunk\ServiceProvider::class); - } - if (isPlugin('HtrunkDocs') && $this->isPluginDir('HtrunkDocs')) { - $this->app->register(\App\Plugins\HtrunkDocs\ServiceProvider::class); - } - if (isPlugin('Licenses') && $this->isPluginDir('Licenses')) { - $this->app->register(\App\Plugins\Licenses\ServiceProvider::class); - } - if (isPlugin('Migration') && $this->isPluginDir('Migration')) { - $this->app->register(\App\Plugins\Migration\ServiceProvider::class); - } - if (isPlugin('Reseller') && $this->isPluginDir('Reseller')) { - $this->app->register(\App\Plugins\Reseller\ServiceProvider::class); - } - if (isPlugin('SMS') && $this->isPluginDir('SMS')) { - $this->app->register(\App\Plugins\SMS\ServiceProvider::class); - } - if (isPlugin('ServiceDesk') && $this->isPluginDir('ServiceDesk')) { - $this->app->register(\App\Plugins\ServiceDesk\ServiceProvider::class); - } - if (isPlugin('Social') && $this->isPluginDir('Social')) { - $this->app->register(\App\Plugins\Social\ServiceProvider::class); - } - if (isPlugin('Telephony') && $this->isPluginDir('Telephony')) { - $this->app->register(\App\Plugins\Telephony\ServiceProvider::class); - } - if (isPlugin('Zapier') && $this->isPluginDir('Zapier')) { - $this->app->register(\App\Plugins\Zapier\ServiceProvider::class); - } - if ($this->isModuleDir('Location')) { - $this->app->register(\App\Location\LocationServiceProvider::class); + $activePlugins = \DB::table('plugins')->select('name', 'path')->where('status', 1)->get(); + foreach ($activePlugins as $activePlugin) { + if ($this->isPluginDir($activePlugin->name)) { + $class = '\App\Plugins\\'.$activePlugin->name.'\ServiceProvider'; + $this->app->register($class); + } } }