123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use DB;
- use Artisan;
- use App\Models\Upload;
- use App\Models\Product;
- use App\Models\Tax;
- use App\Models\ProductTax;
- use App\Models\Seller;
- use App\Models\SellerPackage;
- use App\Models\SellerWithdrawRequest;
- use App\Models\Shop;
- use Schema;
- use Str;
- use ZipArchive;
- class UpdateController extends Controller
- {
- public function step0(Request $request)
- {
- if (env('DEMO_MODE') == 'On') {
- flash(translate('This action is disabled in demo mode'))->error();
- return back();
- }
- if ($request->has('update_zip')) {
- if (class_exists('ZipArchive')) {
- // Create update directory.
- $dir = 'updates';
- if (!is_dir($dir))
- mkdir($dir, 0777, true);
- $path = Upload::findOrFail($request->update_zip)->file_name;
- //Unzip uploaded update file and remove zip file.
- $zip = new ZipArchive;
- $res = $zip->open(base_path('public/' . $path));
- if ($res === true) {
- $res = $zip->extractTo(base_path());
- $zip->close();
- } else {
- flash(translate('Could not open the updates zip file.'))->error();
- return back();
- }
- return redirect()->route('update.step1');
- } else {
- flash(translate('Please enable ZipArchive extension.'))->error();
- }
- } else {
- return view('update.step0');
- }
- }
- public function step1()
- {
- if (get_setting('current_version') == '6.1.1') {
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- }
- if (get_setting('current_version') == '6.1') {
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- }
- if (get_setting('current_version') == '6.0') {
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- }
- if (get_setting('current_version') == '5.5.7') {
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- }
- if (get_setting('current_version') == '5.5.6') {
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.5.5') {
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.5.4') {
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.5.3') {
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.5.2') {
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.5.1') {
- $sql_path = base_path('sqlupdates/v552.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.5') {
- $sql_path = base_path('sqlupdates/v551.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v552.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.4.4') {
- $sql_path = base_path('sqlupdates/v55.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v551.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v552.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.4.3') {
- $sql_path = base_path('sqlupdates/v544.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v55.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v551.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v552.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.4.2') {
- $sql_path = base_path('sqlupdates/v543.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v544.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v55.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v551.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v552.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } elseif (get_setting('current_version') == '5.4.1') {
- $sql_path = base_path('sqlupdates/v542.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v543.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v544.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v55.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v551.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v552.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v553.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v554.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v555.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v556.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v557.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v60.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v61.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v611.sql');
- DB::unprepared(file_get_contents($sql_path));
- $sql_path = base_path('sqlupdates/v612.sql');
- DB::unprepared(file_get_contents($sql_path));
- return redirect()->route('update.step2');
- } else {
- Artisan::call('view:clear');
- Artisan::call('cache:clear');
- $previousRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.php');
- $newRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.txt');
- copy($newRouteServiceProvier, $previousRouteServiceProvier);
- return view('update.done');
- }
- }
- public function step2()
- {
- Artisan::call('view:clear');
- Artisan::call('cache:clear');
- $this->convertSellerIntoShop();
- $this->convertSellerIntoUser();
- $this->convertSellerPackageIntoShop();
- $this->convertTrasnalations();
- // $this->convertColorsName();
- $previousRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.php');
- $newRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.txt');
- copy($newRouteServiceProvier, $previousRouteServiceProvier);
- return view('update.done');
- }
- public function convertSellerIntoShop()
- {
- $sellers = Seller::all();
- foreach ($sellers as $seller) {
- $shop = Shop::where('user_id', $seller->user_id)->first();
- if ($shop) {
- if (!$shop->rating) {
- $shop->rating = $seller->rating;
- $shop->num_of_reviews = $seller->num_of_reviews;
- }
- if (!$shop->num_of_sale) {
- $shop->num_of_sale = $seller->num_of_sale;
- }
- if (!$shop->seller_package_id) {
- $shop->seller_package_id = $seller->seller_package_id;
- $shop->product_upload_limit = $seller->product_upload_limit;
- $shop->package_invalid_at = $seller->invalid_at;
- }
- if ($shop->admin_to_pay == 0) {
- $shop->admin_to_pay = $seller->admin_to_pay;
- }
- $shop->verification_status = $seller->verification_status;
- $shop->verification_info = $seller->verification_info;
- $shop->cash_on_delivery_status = $seller->cash_on_delivery_status;
- if (!$shop->bank_name) {
- $shop->bank_name = $seller->bank_name;
- $shop->bank_acc_name = $seller->bank_acc_name;
- $shop->bank_acc_no = $seller->bank_acc_no;
- $shop->bank_routing_no = $seller->bank_routing_no;
- $shop->bank_payment_status = $seller->bank_payment_status;
- }
- $shop->save();
- }
- }
- }
- public function convertSellerIntoUser()
- {
- $seller_withdraw_requests = SellerWithdrawRequest::all();
- foreach ($seller_withdraw_requests as $seller_withdraw_request) {
- $seller = Seller::where('id', $seller_withdraw_request->user_id)->first();
- if ($seller) {
- $seller_withdraw_request->user_id = $seller->user_id;
- $seller_withdraw_request->save();
- }
- }
- }
- public function convertSellerPackageIntoShop()
- {
- if (Schema::hasTable('seller_packages')) {
- $shops = Shop::all();
- foreach ($shops as $shop) {
- $seller_package = SellerPackage::where('id', $shop->seller_package_id)->first();
- if ($seller_package) {
- $shop->product_upload_limit = $seller_package->product_upload_limit;
- $shop->save();
- }
- }
- }
- }
- public function convertTaxes()
- {
- $tax = Tax::first();
- foreach (Product::all() as $product) {
- $product_tax = new ProductTax;
- $product_tax->product_id = $product->id;
- $product_tax->tax_id = $tax->id;
- $product_tax->tax = $product->tax;
- $product_tax->tax_type = $product->tax_type;
- $product_tax->save();
- }
- }
- public function convertTrasnalations()
- {
- foreach (\App\Models\Translation::all() as $translation) {
- $lang_key = preg_replace('/[^A-Za-z0-9\_]/', '', str_replace(' ', '_', strtolower($translation->lang_key)));
- $translation->lang_key = $lang_key;
- $translation->save();
- }
- }
- public function convertColorsName()
- {
- foreach (\App\Models\Color::all() as $color) {
- $color->name = Str::replace(' ', '', $color->name);
- $color->save();
- }
- }
- public function convertRatingAndSales()
- {
- foreach (\App\Models\Seller::all() as $seller) {
- $total = 0;
- $rating = 0;
- $num_of_sale = 0;
- try {
- foreach ($seller->user->products as $seller_product) {
- $total += $seller_product->reviews->count();
- $rating += $seller_product->reviews->sum('rating');
- $num_of_sale += $seller_product->num_of_sale;
- }
- if ($total > 0) {
- $seller->rating = $rating / $total;
- $seller->num_of_reviews = $total;
- }
- $seller->num_of_sale = $num_of_sale;
- $seller->save();
- } catch (\Exception $e) {
- }
- }
- }
- }
|