芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/yeahea.digitalhubbd.com/app/Services/PackageInstaller.php
, September 2018 */ namespace App\Services; use Carbon\Carbon; use App\Models\Package; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\MessageBag; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Artisan; class PackageInstaller { public $package; public $slug; public $namespace; public $path; public $migrations; public function __construct(Request $request, array $installable) { $this->package = array_merge($installable, $request->all()); $this->slug = $installable["\x73\x6c\x75\x67"]; $this->namespace = "\x5c\x49\x6e\x63\145\x76\151\x6f\x5c\120\x61\x63\153\x61\147\x65\x5c" . Str::studly(Str::replace("\x2d", "\137", $this->slug)); $this->path = $installable["\160\141\x74\x68"]; $this->migrations = str_replace(base_path(), '', $this->path . "\x2f\144\x61\x74\141\x62\x61\x73\x65\57\x6d\x69\x67\x72\x61\164\x69\x6f\x6e\163"); } public function install() { Log::info("\111\156\x73\x74\141\154\x6c\151\x6e\147\x20\x70\x61\143\x6b\141\x67\x65\x20" . $this->slug); try { $package_data = array_merge($this->package, preparePackageInstallation($this->package)); Package::create($package_data); $this->migrate()->seed(); } catch (\Exception $exception) { Log::info("\120\141\x63\153\x61\x67\145\40\151\x6e\163\164\141\x6c\x6c\141\x74\x69\x6f\156\x20\146\141\x69\x6c\x65\x64\40" . $this->slug); Log::error(get_exception_message($exception)); throw new \Exception("\x50\141\143\153\x61\147\x65\x20\111\x6e\x73\164\x61\154\154\141\x74\151\x6f\x6e\x20\106\x61\x69\x6c\145\x64\x20" . $this->slug); } Log::info("\x53\165\143\143\x65\x73\x73\x66\x75\x6c\154\x79\40\151\x6e\x73\164\x61\x6c\154\145\144\40\x70\x61\143\153\141\147\x65\x20" . $this->slug); return true; } public function upgrade() { Log::info("\x55\160\147\x72\141\x64\145\x69\x6e\x67\x20\160\141\x63\x6b\141\147\x65\40" . $this->slug); try { $package_data = array_merge($this->package, preparePackageInstallation($this->package)); Package::where("\163\x6c\x75\x67", $this->slug)->update(["\156\141\x6d\x65" => $package_data["\156\141\155\145"], "\144\145\x73\x63\x72\x69\160\x74\x69\x6f\x6e" => $package_data["\x64\145\163\x63\x72\x69\x70\x74\x69\x6f\156"], "\143\157\155\x70\x61\164\x69\142\x6c\145" => $package_data["\x63\157\155\160\x61\x74\151\142\154\145"], "\166\145\162\163\151\157\x6e" => $package_data["\166\145\162\163\151\x6f\x6e"], "\151\x63\157\156" => $package_data["\151\x63\x6f\156"], "\x64\145\160\145\156\144\145\x6e\143\x79" => $package_data["\144\145\160\x65\x6e\x64\145\x6e\x63\171"], "\x75\x70\144\x61\x74\145\144\137\x61\x74" => Carbon::Now()]); $this->migrate(); } catch (\Exception $exception) { Log::info("\x50\x61\x63\153\x61\147\x65\40\x75\x70\147\162\x61\144\x61\164\x69\x6f\156\x20\146\141\x69\x6c\x65\x64\x20" . $this->slug); Log::error(get_exception_message($exception)); throw new \Exception("\120\x61\x63\153\141\x67\x65\40\x75\160\x67\162\141\144\141\x74\151\x6f\x6e\40\146\141\151\x6c\x65\144\40" . $this->slug); } Log::info("\x53\165\x63\143\x65\x73\163\146\165\154\154\171\x20\x75\x70\147\162\x61\x64\x65\144\40\x70\x61\x63\x6b\141\x67\x65\40" . $this->slug); return true; } public function migrate() { Log::info("\115\151\x67\x72\141\164\151\157\156\x20\163\164\x61\162\x74\145\144\x20\146\x6f\x72\x20" . $this->slug); Artisan::call("\x6d\x69\147\162\141\x74\145", ["\x2d\x2d\x70\x61\x74\150" => $this->migrations, "\55\x2d\x66\157\162\x63\145" => true]); Log::info(Artisan::output()); return $this; } private function seed() { Log::info("\123\145\145\x64\x69\x6e\x67\40\x70\141\143\153\x61\147\145\40\x64\x61\x74\141\x20\146\157\162\40" . $this->slug); foreach (glob($this->path . "\x2f\144\x61\164\x61\x62\141\x73\x65\57\x73\x65\x65\144\163\57\x2a\56\x70\150\160") as $filename) { $classes = get_declared_classes(); include $filename; $temp = array_diff(get_declared_classes(), $classes); $migration = Arr::last($temp, function ($value, $key) { return $value !== "\x49\x6c\x6c\165\x6d\151\x6e\141\x74\x65\134\104\x61\x74\141\x62\x61\x73\x65\x5c\x53\x65\145\144\145\162"; }); Artisan::call("\144\x62\72\163\x65\145\144", ["\x2d\x2d\143\x6c\x61\x73\x73" => $migration, "\x2d\x2d\146\157\162\x63\145" => true]); Log::info(Artisan::output()); AsJiA: } V3GDu: return $this; } public function uninstall() { Log::info("\x55\156\151\156\x73\x74\x61\x6c\x6c\151\x6e\x67\x20\x50\141\x63\x6b\141\x67\x65\x3a\x20" . $this->slug); $file = $this->path . "\57\163\x72\143\x2f\125\x6e\x69\156\x73\164\x61\x6c\154\x65\162\56\160\150\160"; if (!file_exists($file)) { goto FEeD0; } include $file; FEeD0: $class = $this->namespace . "\134\125\156\x69\x6e\x73\x74\141\x6c\x6c\145\162"; if (class_exists($class)) { goto BBTRV; } Log::info("\125\156\x69\156\163\164\141\154\154\145\x72\40\x6e\x6f\x74\x20\146\x6f\165\x6e\144\x20\151\156\x20\164\x68\x65\40\160\141\143\153\x61\x67\145\40\x64\x69\162\40\x66\x6f\x72\40" . $this->slug); throw new \Exception("\x55\156\151\x6e\x73\x74\141\x6c\x6c\x65\162\40\x6e\157\164\40\x66\x6f\x75\x6e\x64\40\x66\157\x72\x20\x74\x68\145\40\x70\141\143\x6b\141\147\x65\40" . $this->slug); BBTRV: try { (new $class())->cleanDatabase(); $this->rollback(); } catch (\Exception $e) { Log::info("\120\141\x63\x6b\141\x67\x65\40\165\156\151\x6e\x73\164\141\x6c\154\141\164\151\157\x6e\x20\x66\141\x69\154\x65\144\x3a\40" . $this->slug); Log::error($e); throw new \Exception("\125\x6e\x69\x6e\x73\x74\x61\x6c\x6c\x61\x74\151\157\156\x20\146\141\x69\x6c\145\x64\x3a\x20" . $this->slug); } Log::info("\123\165\x63\143\145\163\163\146\165\x6c\x6c\171\40\x75\x6e\151\x6e\x73\x74\141\x6c\154\145\144\40\160\141\143\153\x61\x67\145\x20" . $this->slug); return $this; } private function rollback() { Log::info("\122\x6f\x6c\x6c\40\x62\141\x63\153\x20\x63\141\x6c\x6c\x65\x64\56\x2e\x2e"); $migrations = array_reverse(glob($this->path . "\x2f\x64\x61\164\141\142\x61\163\145\x2f\155\x69\x67\x72\141\x74\x69\157\156\163\57\x2a\137\x2a\56\160\150\x70")); if (!empty($migrations)) { goto BE42U; } Log::info("\116\157\x20\x6d\x69\147\x72\x61\164\x69\x6f\156\x20\x74\157\40\162\x6f\154\x6c\x20\x62\x61\x63\153\40\146\x6f\x72\40\160\x61\x63\153\x61\147\145\40" . $this->slug); return $this; BE42U: Schema::disableForeignKeyConstraints(); DB::statement("\123\x45\124\x20\x46\x4f\122\105\111\x47\x4e\x5f\x4b\105\x59\137\x43\x48\x45\103\x4b\x53\40\75\40\60"); foreach ($migrations as $filename) { $migration = str_replace("\x2e\160\150\x70", '', basename($filename)); Log::info("\122\157\154\154\x69\x6e\x67\x20\142\x61\143\153\x3a\x20" . $migration); $row = DB::table("\155\151\x67\162\x61\x74\x69\157\156\163")->where("\x6d\151\147\x72\x61\164\x69\157\x6e", $migration); if ($row->first()) { goto k7KAF; } Log::info($migration . "\x20\167\x61\x73\40\156\x6f\x74\x20\155\151\x67\x72\x61\x74\x65\144\x20\142\x65\x66\157\162\x65\54\x20\160\x72\x6f\x62\x61\142\154\x79\40\x69\164\x5c\47\163\x20\x61\40\156\x65\167\x20\x6d\151\147\162\141\164\151\x6f\156\40\x66\x69\x6c\145\56"); Log::info("\123\x6b\x69\160\x70\x69\x6e\147\40\x72\157\154\x6c\145\144\40\142\x61\143\153\x3a\x20" . $migration); goto sNJRq; k7KAF: $class = Str::studly(implode("\137", array_slice(explode("\x5f", $migration), 4))); if (class_exists($class)) { goto YGwAm; } include $filename; YGwAm: (new $class())->down(); if ($row->delete()) { goto THOrD; } Log::info("\122\x6f\154\154\x62\141\143\x6b\x20\106\101\111\x4c\x45\x44\72\40" . $migration); throw new \Exception("\115\x69\147\x72\x61\x74\151\x6f\x6e\x20\x72\157\x6c\154\x62\x61\143\153\x20\146\x61\151\x6c\145\144\72\40" . $this->slug); goto UhcjG; THOrD: Log::info("\x52\157\154\154\145\144\x20\142\141\x63\x6b\x3a\40" . $migration); UhcjG: sNJRq: } gOf8K: Schema::enableForeignKeyConstraints(); DB::statement("\123\x45\x54\40\x46\x4f\122\x45\111\107\x4e\137\113\105\131\137\103\110\x45\x43\x4b\123\x20\x3d\x20\x31"); Log::info("\x41\x6c\154\40\155\x69\147\162\141\x74\151\157\x6e\x73\40\150\141\x73\x20\x62\145\x65\156\x20\x72\157\154\x6c\145\x64\x20\x62\141\x63\153\40\146\157\162\x20\x70\141\x63\153\141\x67\x65\x20" . $this->slug); return $this; } }