UpdateVersion.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Artisan;
  5. class UpdateVersion extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'update:version {version}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '应用更新';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. //$this->createPluginFile();
  36. if(app()->environment() == 'production'){
  37. $this->runMigrate();
  38. }
  39. }
  40. public function runMigrate()
  41. {
  42. //更新商城数据表
  43. \Artisan::call('migrate',['--force' => true]);
  44. //更新插件数据表
  45. $plugins = $this->argument('version');
  46. \Log::debug('---plugins---', $plugins);
  47. if (!is_null($plugins)) {
  48. foreach ($plugins as $p) {
  49. if (app('plugins')->getPlugin($p)) {
  50. $path = 'plugins/' . $p . '/migrations';
  51. if(is_dir(base_path($path) )){
  52. \Artisan::call('migrate',['--force' => true,'--path' => $path]);
  53. }
  54. }
  55. }
  56. }
  57. //更新数据表
  58. $versionMigration = 'database/migrations/' . $username = $this->argument('version');
  59. if(is_dir(base_path($versionMigration) )){
  60. \Artisan::call('migrate',['--force' => true,'--path' => $versionMigration]);
  61. }
  62. \Log::debug('数据迁移');
  63. \Artisan::call('db:seed', ['--force' => true]);
  64. }
  65. public function createPluginFile()
  66. {
  67. $pluginFile = base_path('../../web') . '/plugin.php';
  68. if(!file_exists($pluginFile)){
  69. file_put_contents($pluginFile,"<?php
  70. define('IN_IA', true);
  71. include_once __DIR__ . '/../addons/yun_shop/app/laravel.php';
  72. include_once __DIR__ . '/../addons/yun_shop/app/yunshop.php';
  73. ");
  74. }
  75. }
  76. }