Plugin updates

* Changed plugin settings to activate and deactivate plugin by removing update process for config/app.php file.
* Changed plugin ServiceProvider registration technique by removing hard coded code in AppServiceProvider. Now We are registering all plugins's ServiceProvider classes avaliable for active plugins with status as 1 in plugins table in database. It provides more dynaamicity to developers so they need not to worry about registering their custom plugin's ServiceProvider.
This commit is contained in:
Manish Verma
2018-11-14 12:46:05 +05:30
committed by Manish Verma
parent 7dbeaafe16
commit 1e7a891d3a
2 changed files with 11 additions and 79 deletions

View File

@@ -406,18 +406,6 @@ class SettingsController extends Controller
*/ */
$faveoconfig = config_path().DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$filename.'.php'; $faveoconfig = config_path().DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$filename.'.php';
if ($faveoconfig) { 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]); $plug->create(['name' => $filename, 'path' => $filename, 'status' => 1]);
return redirect()->back()->with('success', Lang::get('lang.plugin-installed')); return redirect()->back()->with('success', Lang::get('lang.plugin-installed'));
@@ -584,12 +572,6 @@ class SettingsController extends Controller
$plugs = new Plugin(); $plugs = new Plugin();
$plug = $plugs->where('name', $slug)->first(); $plug = $plugs->where('name', $slug)->first();
if (!$plug) { 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]); $plugs->create(['name' => $slug, 'path' => $slug, 'status' => 1]);
return redirect()->back()->with('success', 'Status has changed'); return redirect()->back()->with('success', 'Status has changed');
@@ -597,25 +579,9 @@ class SettingsController extends Controller
$status = $plug->status; $status = $plug->status;
if ($status == 0) { if ($status == 0) {
$plug->status = 1; $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) { if ($status == 1) {
$plug->status = 0; $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(); $plug->save();

View File

@@ -3,6 +3,7 @@
namespace App\Providers; namespace App\Providers;
use App\Model\Update\BarNotification; use App\Model\Update\BarNotification;
use App\Model\helpdesk\Settings\Plugin;
use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Events\JobFailed;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -28,9 +29,9 @@ class AppServiceProvider extends ServiceProvider
if ($this->app->environment('local', 'testing')) { if ($this->app->environment('local', 'testing')) {
$this->app->register(DuskServiceProvider::class); $this->app->register(DuskServiceProvider::class);
} }
// if (isInstall()) { if (isInstall()) {
// $this->plugin(); $this->registerPlugin();
// } }
} }
public function boot() public function boot()
@@ -53,49 +54,14 @@ class AppServiceProvider extends ServiceProvider
}); });
} }
public function plugin() public function registerPlugin()
{ {
if (isPlugin('Ldap') && $this->isPluginDir('Ldap')) { $activePlugins = \DB::table('plugins')->select('name', 'path')->where('status', 1)->get();
$this->app->register(\App\Plugins\Ldap\ServiceProvider::class); foreach ($activePlugins as $activePlugin) {
} if ($this->isPluginDir($activePlugin->name)) {
if (isPlugin('Chat') && $this->isPluginDir('Chat')) { $class = '\App\Plugins\\'.$activePlugin->name.'\ServiceProvider';
$this->app->register(\App\Plugins\Chat\ServiceProvider::class); $this->app->register($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);
} }
} }