auto-update
This commit is contained in:
		
							
								
								
									
										34
									
								
								app/Console/Commands/Sync.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								app/Console/Commands/Sync.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Console\Commands; | ||||
|  | ||||
| use App\Http\Controllers\Update\SyncFaveoToLatestVersion; | ||||
| use Illuminate\Console\Command; | ||||
|  | ||||
| class Sync extends Command | ||||
| { | ||||
|     /** | ||||
|      * The name and signature of the console command. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $signature = 'database:sync'; | ||||
|  | ||||
|     /** | ||||
|      * The console command description. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $description = 'Migration and Database seeder'; | ||||
|  | ||||
|     /** | ||||
|      * Execute the console command. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         (new SyncFaveoToLatestVersion())->sync(); | ||||
|         return Command::SUCCESS; | ||||
|     } | ||||
| } | ||||
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Installer\helpdesk; | ||||
| // controllers | ||||
| use App\Http\Controllers\Controller; | ||||
| // requests | ||||
| use App\Http\Controllers\Update\SyncFaveoToLatestVersion; | ||||
| use App\Http\Requests\helpdesk\InstallerRequest; | ||||
| use App\Model\helpdesk\Settings\System; | ||||
| // models | ||||
| @@ -435,6 +436,7 @@ class InstallController extends Controller | ||||
|         $ENV['DB_DATABASE'] = '"'.$database.'"'; | ||||
|         $ENV['DB_USERNAME'] = '"'.$dbusername.'"'; | ||||
|         $ENV['DB_PASSWORD'] = '"'.$dbpassword.'"'; | ||||
|         $ENV['DB_ENGINE']   = 'InnoDB'; | ||||
|         $ENV['MAIL_MAILER'] = 'smtp'; | ||||
|         $ENV['MAIL_HOST'] = 'mailtrap.io'; | ||||
|         $ENV['MAIL_PORT'] = '2525'; | ||||
| @@ -490,29 +492,23 @@ class InstallController extends Controller | ||||
|  | ||||
|     public function migrate() | ||||
|     { | ||||
|         $db_install_method = ''; | ||||
|  | ||||
|         try { | ||||
|             $tableNames = \Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); | ||||
|             $tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); | ||||
|             if (count($tableNames) === 0) { | ||||
|                 if (!Cache::get('dummy_data_installation')) { | ||||
|                     Artisan::call('migrate', ['--force' => true]); | ||||
|                     $db_install_method = 'migrate'; | ||||
|                 } else { | ||||
|                 (new SyncFaveoToLatestVersion())->sync(); | ||||
|                 if (Cache::get('dummy_data_installation')) { | ||||
|                     $path = base_path().DIRECTORY_SEPARATOR.'DB'.DIRECTORY_SEPARATOR.'dummy-data.sql'; | ||||
|                     DB::unprepared(file_get_contents($path)); | ||||
|                     $db_install_method = 'dump'; | ||||
|                 } | ||||
|             } | ||||
|         } catch (Exception $ex) { | ||||
|             dd($ex); | ||||
|             $this->rollBackMigration(); | ||||
|             $result = ['error' => $ex->getMessage()]; | ||||
|  | ||||
|             return response()->json(compact('result'), 500); | ||||
|         } | ||||
|         $url = ($db_install_method == 'migrate') ? url('seed') : ''; | ||||
|         $message = ($db_install_method == 'migrate') ? 'Tables have been migrated successfully in database.' : 'Database has been setup successfully.'; | ||||
|         $result = ['success' => $message, 'next' => 'Seeding pre configurations data', 'api' => $url]; | ||||
|         $result = ['success' => 'Database has been setup successfully.']; | ||||
|  | ||||
|         return response()->json(compact('result')); | ||||
|     } | ||||
|   | ||||
							
								
								
									
										64
									
								
								app/Http/Controllers/Update/SyncFaveoToLatestVersion.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								app/Http/Controllers/Update/SyncFaveoToLatestVersion.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Http\Controllers\Update; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Model\helpdesk\Settings\System; | ||||
| use Exception; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Artisan; | ||||
| use Illuminate\Support\Facades\Config; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
| use Illuminate\Support\Str; | ||||
|  | ||||
| class SyncFaveoToLatestVersion extends Controller | ||||
| { | ||||
|     public function sync() | ||||
|     { | ||||
|         ini_set('memory_limit', '-1'); | ||||
|         ini_set('max_execution_time', '-1'); | ||||
|         set_time_limit(0); | ||||
|  | ||||
|         $latestVersion = $this->getPhpComaptibleVersion(Config::get('app.version')); | ||||
|         $olderVersion  = $this->getOlderVersion(); | ||||
|  | ||||
|         if (version_compare($latestVersion, $olderVersion) == 1) { | ||||
|             $this->updateToLatestVersion($olderVersion); | ||||
|         } | ||||
|         System::first()->update(['version' => Config::get('app.version')]); | ||||
|     } | ||||
|  | ||||
|     private function updateToLatestVersion($olderVersion) | ||||
|     { | ||||
|         Artisan::call('migrate', ['--force' => true]); | ||||
|  | ||||
|         $seederPath = base_path('database'.DIRECTORY_SEPARATOR.'seeders'); | ||||
|  | ||||
|         if(file_exists($seederPath)){ | ||||
|             $seederVersions = scandir($seederPath); | ||||
|  | ||||
|             natsort($seederVersions); | ||||
|             $formattedOlderVersion = $olderVersion; | ||||
|             foreach ($seederVersions as $version) { | ||||
|                 if(version_compare($this->getPhpComaptibleVersion($version), $formattedOlderVersion) == 1){ | ||||
|                     Artisan::call('db:seed',['--class' => "Database\Seeders\\$version\DatabaseSeeder", '--force' => true]); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function getOlderVersion() | ||||
|     { | ||||
|         if (!isInstall()) { | ||||
|             return '0.0.0'; | ||||
|         } | ||||
|  | ||||
|         $version = System::value('version') ?: '0.0.0'; | ||||
|         return $this->getPhpComaptibleVersion($version); | ||||
|     } | ||||
|  | ||||
|     private function getPhpComaptibleVersion($version) | ||||
|     { | ||||
|         return preg_replace('#v\.|v#', '', str_replace('_', '.', $version)); | ||||
|     } | ||||
| } | ||||
| @@ -13,6 +13,6 @@ class System extends BaseModel | ||||
|     protected $fillable = [ | ||||
|  | ||||
|         'id', 'status', 'url', 'name', 'department', 'page_size', 'log_level', 'purge_log', 'name_format', | ||||
|         'time_farmat', 'date_format', 'date_time_format', 'day_date_time', 'time_zone', 'content', 'api_key', 'api_enable', 'api_key_mandatory', | ||||
|         'time_farmat', 'date_format', 'date_time_format', 'day_date_time', 'time_zone', 'content', 'api_key', 'api_enable', 'api_key_mandatory', 'version' | ||||
|     ]; | ||||
| } | ||||
|   | ||||
| @@ -2,8 +2,10 @@ | ||||
|  | ||||
| namespace App\Providers; | ||||
|  | ||||
| use App\Model\helpdesk\Settings\System; | ||||
| use App\Model\Update\BarNotification; | ||||
| use Illuminate\Queue\Events\JobFailed; | ||||
| use Illuminate\Support\Facades\Config; | ||||
| use Illuminate\Support\Facades\Route; | ||||
| use Illuminate\Support\ServiceProvider; | ||||
| use Laravel\Dusk\DuskServiceProvider; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 RafficMohammed
					RafficMohammed