UpdateController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use DB;
  5. use Artisan;
  6. use App\Models\Upload;
  7. use App\Models\Product;
  8. use App\Models\Tax;
  9. use App\Models\ProductTax;
  10. use App\Models\Seller;
  11. use App\Models\SellerPackage;
  12. use App\Models\SellerWithdrawRequest;
  13. use App\Models\Shop;
  14. use Schema;
  15. use Str;
  16. use ZipArchive;
  17. class UpdateController extends Controller
  18. {
  19. public function step0(Request $request)
  20. {
  21. if (env('DEMO_MODE') == 'On') {
  22. flash(translate('This action is disabled in demo mode'))->error();
  23. return back();
  24. }
  25. if ($request->has('update_zip')) {
  26. if (class_exists('ZipArchive')) {
  27. // Create update directory.
  28. $dir = 'updates';
  29. if (!is_dir($dir))
  30. mkdir($dir, 0777, true);
  31. $path = Upload::findOrFail($request->update_zip)->file_name;
  32. //Unzip uploaded update file and remove zip file.
  33. $zip = new ZipArchive;
  34. $res = $zip->open(base_path('public/' . $path));
  35. if ($res === true) {
  36. $res = $zip->extractTo(base_path());
  37. $zip->close();
  38. } else {
  39. flash(translate('Could not open the updates zip file.'))->error();
  40. return back();
  41. }
  42. return redirect()->route('update.step1');
  43. } else {
  44. flash(translate('Please enable ZipArchive extension.'))->error();
  45. }
  46. } else {
  47. return view('update.step0');
  48. }
  49. }
  50. public function step1()
  51. {
  52. if (get_setting('current_version') == '6.1.1') {
  53. $sql_path = base_path('sqlupdates/v612.sql');
  54. DB::unprepared(file_get_contents($sql_path));
  55. return redirect()->route('update.step2');
  56. }
  57. if (get_setting('current_version') == '6.1') {
  58. $sql_path = base_path('sqlupdates/v611.sql');
  59. DB::unprepared(file_get_contents($sql_path));
  60. $sql_path = base_path('sqlupdates/v612.sql');
  61. DB::unprepared(file_get_contents($sql_path));
  62. return redirect()->route('update.step2');
  63. }
  64. if (get_setting('current_version') == '6.0') {
  65. $sql_path = base_path('sqlupdates/v61.sql');
  66. DB::unprepared(file_get_contents($sql_path));
  67. $sql_path = base_path('sqlupdates/v611.sql');
  68. DB::unprepared(file_get_contents($sql_path));
  69. $sql_path = base_path('sqlupdates/v612.sql');
  70. DB::unprepared(file_get_contents($sql_path));
  71. return redirect()->route('update.step2');
  72. }
  73. if (get_setting('current_version') == '5.5.7') {
  74. $sql_path = base_path('sqlupdates/v60.sql');
  75. DB::unprepared(file_get_contents($sql_path));
  76. $sql_path = base_path('sqlupdates/v61.sql');
  77. DB::unprepared(file_get_contents($sql_path));
  78. $sql_path = base_path('sqlupdates/v611.sql');
  79. DB::unprepared(file_get_contents($sql_path));
  80. $sql_path = base_path('sqlupdates/v612.sql');
  81. DB::unprepared(file_get_contents($sql_path));
  82. return redirect()->route('update.step2');
  83. }
  84. if (get_setting('current_version') == '5.5.6') {
  85. $sql_path = base_path('sqlupdates/v557.sql');
  86. DB::unprepared(file_get_contents($sql_path));
  87. $sql_path = base_path('sqlupdates/v60.sql');
  88. DB::unprepared(file_get_contents($sql_path));
  89. $sql_path = base_path('sqlupdates/v61.sql');
  90. DB::unprepared(file_get_contents($sql_path));
  91. $sql_path = base_path('sqlupdates/v611.sql');
  92. DB::unprepared(file_get_contents($sql_path));
  93. $sql_path = base_path('sqlupdates/v612.sql');
  94. DB::unprepared(file_get_contents($sql_path));
  95. return redirect()->route('update.step2');
  96. } elseif (get_setting('current_version') == '5.5.5') {
  97. $sql_path = base_path('sqlupdates/v556.sql');
  98. DB::unprepared(file_get_contents($sql_path));
  99. $sql_path = base_path('sqlupdates/v557.sql');
  100. DB::unprepared(file_get_contents($sql_path));
  101. $sql_path = base_path('sqlupdates/v60.sql');
  102. DB::unprepared(file_get_contents($sql_path));
  103. $sql_path = base_path('sqlupdates/v61.sql');
  104. DB::unprepared(file_get_contents($sql_path));
  105. $sql_path = base_path('sqlupdates/v611.sql');
  106. DB::unprepared(file_get_contents($sql_path));
  107. $sql_path = base_path('sqlupdates/v612.sql');
  108. DB::unprepared(file_get_contents($sql_path));
  109. return redirect()->route('update.step2');
  110. } elseif (get_setting('current_version') == '5.5.4') {
  111. $sql_path = base_path('sqlupdates/v555.sql');
  112. DB::unprepared(file_get_contents($sql_path));
  113. $sql_path = base_path('sqlupdates/v556.sql');
  114. DB::unprepared(file_get_contents($sql_path));
  115. $sql_path = base_path('sqlupdates/v557.sql');
  116. DB::unprepared(file_get_contents($sql_path));
  117. $sql_path = base_path('sqlupdates/v60.sql');
  118. DB::unprepared(file_get_contents($sql_path));
  119. $sql_path = base_path('sqlupdates/v61.sql');
  120. DB::unprepared(file_get_contents($sql_path));
  121. $sql_path = base_path('sqlupdates/v611.sql');
  122. DB::unprepared(file_get_contents($sql_path));
  123. $sql_path = base_path('sqlupdates/v612.sql');
  124. DB::unprepared(file_get_contents($sql_path));
  125. return redirect()->route('update.step2');
  126. } elseif (get_setting('current_version') == '5.5.3') {
  127. $sql_path = base_path('sqlupdates/v554.sql');
  128. DB::unprepared(file_get_contents($sql_path));
  129. $sql_path = base_path('sqlupdates/v555.sql');
  130. DB::unprepared(file_get_contents($sql_path));
  131. $sql_path = base_path('sqlupdates/v556.sql');
  132. DB::unprepared(file_get_contents($sql_path));
  133. $sql_path = base_path('sqlupdates/v557.sql');
  134. DB::unprepared(file_get_contents($sql_path));
  135. $sql_path = base_path('sqlupdates/v60.sql');
  136. DB::unprepared(file_get_contents($sql_path));
  137. $sql_path = base_path('sqlupdates/v61.sql');
  138. DB::unprepared(file_get_contents($sql_path));
  139. $sql_path = base_path('sqlupdates/v611.sql');
  140. DB::unprepared(file_get_contents($sql_path));
  141. $sql_path = base_path('sqlupdates/v612.sql');
  142. DB::unprepared(file_get_contents($sql_path));
  143. return redirect()->route('update.step2');
  144. } elseif (get_setting('current_version') == '5.5.2') {
  145. $sql_path = base_path('sqlupdates/v553.sql');
  146. DB::unprepared(file_get_contents($sql_path));
  147. $sql_path = base_path('sqlupdates/v554.sql');
  148. DB::unprepared(file_get_contents($sql_path));
  149. $sql_path = base_path('sqlupdates/v555.sql');
  150. DB::unprepared(file_get_contents($sql_path));
  151. $sql_path = base_path('sqlupdates/v556.sql');
  152. DB::unprepared(file_get_contents($sql_path));
  153. $sql_path = base_path('sqlupdates/v557.sql');
  154. DB::unprepared(file_get_contents($sql_path));
  155. $sql_path = base_path('sqlupdates/v60.sql');
  156. DB::unprepared(file_get_contents($sql_path));
  157. $sql_path = base_path('sqlupdates/v61.sql');
  158. DB::unprepared(file_get_contents($sql_path));
  159. $sql_path = base_path('sqlupdates/v611.sql');
  160. DB::unprepared(file_get_contents($sql_path));
  161. $sql_path = base_path('sqlupdates/v612.sql');
  162. DB::unprepared(file_get_contents($sql_path));
  163. return redirect()->route('update.step2');
  164. } elseif (get_setting('current_version') == '5.5.1') {
  165. $sql_path = base_path('sqlupdates/v552.sql');
  166. DB::unprepared(file_get_contents($sql_path));
  167. $sql_path = base_path('sqlupdates/v553.sql');
  168. DB::unprepared(file_get_contents($sql_path));
  169. $sql_path = base_path('sqlupdates/v554.sql');
  170. DB::unprepared(file_get_contents($sql_path));
  171. $sql_path = base_path('sqlupdates/v555.sql');
  172. DB::unprepared(file_get_contents($sql_path));
  173. $sql_path = base_path('sqlupdates/v556.sql');
  174. DB::unprepared(file_get_contents($sql_path));
  175. $sql_path = base_path('sqlupdates/v557.sql');
  176. DB::unprepared(file_get_contents($sql_path));
  177. $sql_path = base_path('sqlupdates/v60.sql');
  178. DB::unprepared(file_get_contents($sql_path));
  179. $sql_path = base_path('sqlupdates/v61.sql');
  180. DB::unprepared(file_get_contents($sql_path));
  181. $sql_path = base_path('sqlupdates/v611.sql');
  182. DB::unprepared(file_get_contents($sql_path));
  183. $sql_path = base_path('sqlupdates/v612.sql');
  184. DB::unprepared(file_get_contents($sql_path));
  185. return redirect()->route('update.step2');
  186. } elseif (get_setting('current_version') == '5.5') {
  187. $sql_path = base_path('sqlupdates/v551.sql');
  188. DB::unprepared(file_get_contents($sql_path));
  189. $sql_path = base_path('sqlupdates/v552.sql');
  190. DB::unprepared(file_get_contents($sql_path));
  191. $sql_path = base_path('sqlupdates/v553.sql');
  192. DB::unprepared(file_get_contents($sql_path));
  193. $sql_path = base_path('sqlupdates/v554.sql');
  194. DB::unprepared(file_get_contents($sql_path));
  195. $sql_path = base_path('sqlupdates/v555.sql');
  196. DB::unprepared(file_get_contents($sql_path));
  197. $sql_path = base_path('sqlupdates/v556.sql');
  198. DB::unprepared(file_get_contents($sql_path));
  199. $sql_path = base_path('sqlupdates/v557.sql');
  200. DB::unprepared(file_get_contents($sql_path));
  201. $sql_path = base_path('sqlupdates/v60.sql');
  202. DB::unprepared(file_get_contents($sql_path));
  203. $sql_path = base_path('sqlupdates/v61.sql');
  204. DB::unprepared(file_get_contents($sql_path));
  205. $sql_path = base_path('sqlupdates/v611.sql');
  206. DB::unprepared(file_get_contents($sql_path));
  207. $sql_path = base_path('sqlupdates/v612.sql');
  208. DB::unprepared(file_get_contents($sql_path));
  209. return redirect()->route('update.step2');
  210. } elseif (get_setting('current_version') == '5.4.4') {
  211. $sql_path = base_path('sqlupdates/v55.sql');
  212. DB::unprepared(file_get_contents($sql_path));
  213. $sql_path = base_path('sqlupdates/v551.sql');
  214. DB::unprepared(file_get_contents($sql_path));
  215. $sql_path = base_path('sqlupdates/v552.sql');
  216. DB::unprepared(file_get_contents($sql_path));
  217. $sql_path = base_path('sqlupdates/v553.sql');
  218. DB::unprepared(file_get_contents($sql_path));
  219. $sql_path = base_path('sqlupdates/v554.sql');
  220. DB::unprepared(file_get_contents($sql_path));
  221. $sql_path = base_path('sqlupdates/v555.sql');
  222. DB::unprepared(file_get_contents($sql_path));
  223. $sql_path = base_path('sqlupdates/v556.sql');
  224. DB::unprepared(file_get_contents($sql_path));
  225. $sql_path = base_path('sqlupdates/v557.sql');
  226. DB::unprepared(file_get_contents($sql_path));
  227. $sql_path = base_path('sqlupdates/v60.sql');
  228. DB::unprepared(file_get_contents($sql_path));
  229. $sql_path = base_path('sqlupdates/v61.sql');
  230. DB::unprepared(file_get_contents($sql_path));
  231. $sql_path = base_path('sqlupdates/v611.sql');
  232. DB::unprepared(file_get_contents($sql_path));
  233. $sql_path = base_path('sqlupdates/v612.sql');
  234. DB::unprepared(file_get_contents($sql_path));
  235. return redirect()->route('update.step2');
  236. } elseif (get_setting('current_version') == '5.4.3') {
  237. $sql_path = base_path('sqlupdates/v544.sql');
  238. DB::unprepared(file_get_contents($sql_path));
  239. $sql_path = base_path('sqlupdates/v55.sql');
  240. DB::unprepared(file_get_contents($sql_path));
  241. $sql_path = base_path('sqlupdates/v551.sql');
  242. DB::unprepared(file_get_contents($sql_path));
  243. $sql_path = base_path('sqlupdates/v552.sql');
  244. DB::unprepared(file_get_contents($sql_path));
  245. $sql_path = base_path('sqlupdates/v553.sql');
  246. DB::unprepared(file_get_contents($sql_path));
  247. $sql_path = base_path('sqlupdates/v554.sql');
  248. DB::unprepared(file_get_contents($sql_path));
  249. $sql_path = base_path('sqlupdates/v555.sql');
  250. DB::unprepared(file_get_contents($sql_path));
  251. $sql_path = base_path('sqlupdates/v556.sql');
  252. DB::unprepared(file_get_contents($sql_path));
  253. $sql_path = base_path('sqlupdates/v557.sql');
  254. DB::unprepared(file_get_contents($sql_path));
  255. $sql_path = base_path('sqlupdates/v60.sql');
  256. DB::unprepared(file_get_contents($sql_path));
  257. $sql_path = base_path('sqlupdates/v61.sql');
  258. DB::unprepared(file_get_contents($sql_path));
  259. $sql_path = base_path('sqlupdates/v611.sql');
  260. DB::unprepared(file_get_contents($sql_path));
  261. $sql_path = base_path('sqlupdates/v612.sql');
  262. DB::unprepared(file_get_contents($sql_path));
  263. return redirect()->route('update.step2');
  264. } elseif (get_setting('current_version') == '5.4.2') {
  265. $sql_path = base_path('sqlupdates/v543.sql');
  266. DB::unprepared(file_get_contents($sql_path));
  267. $sql_path = base_path('sqlupdates/v544.sql');
  268. DB::unprepared(file_get_contents($sql_path));
  269. $sql_path = base_path('sqlupdates/v55.sql');
  270. DB::unprepared(file_get_contents($sql_path));
  271. $sql_path = base_path('sqlupdates/v551.sql');
  272. DB::unprepared(file_get_contents($sql_path));
  273. $sql_path = base_path('sqlupdates/v552.sql');
  274. DB::unprepared(file_get_contents($sql_path));
  275. $sql_path = base_path('sqlupdates/v553.sql');
  276. DB::unprepared(file_get_contents($sql_path));
  277. $sql_path = base_path('sqlupdates/v554.sql');
  278. DB::unprepared(file_get_contents($sql_path));
  279. $sql_path = base_path('sqlupdates/v555.sql');
  280. DB::unprepared(file_get_contents($sql_path));
  281. $sql_path = base_path('sqlupdates/v556.sql');
  282. DB::unprepared(file_get_contents($sql_path));
  283. $sql_path = base_path('sqlupdates/v557.sql');
  284. DB::unprepared(file_get_contents($sql_path));
  285. $sql_path = base_path('sqlupdates/v60.sql');
  286. DB::unprepared(file_get_contents($sql_path));
  287. $sql_path = base_path('sqlupdates/v61.sql');
  288. DB::unprepared(file_get_contents($sql_path));
  289. $sql_path = base_path('sqlupdates/v611.sql');
  290. DB::unprepared(file_get_contents($sql_path));
  291. $sql_path = base_path('sqlupdates/v612.sql');
  292. DB::unprepared(file_get_contents($sql_path));
  293. return redirect()->route('update.step2');
  294. } elseif (get_setting('current_version') == '5.4.1') {
  295. $sql_path = base_path('sqlupdates/v542.sql');
  296. DB::unprepared(file_get_contents($sql_path));
  297. $sql_path = base_path('sqlupdates/v543.sql');
  298. DB::unprepared(file_get_contents($sql_path));
  299. $sql_path = base_path('sqlupdates/v544.sql');
  300. DB::unprepared(file_get_contents($sql_path));
  301. $sql_path = base_path('sqlupdates/v55.sql');
  302. DB::unprepared(file_get_contents($sql_path));
  303. $sql_path = base_path('sqlupdates/v551.sql');
  304. DB::unprepared(file_get_contents($sql_path));
  305. $sql_path = base_path('sqlupdates/v552.sql');
  306. DB::unprepared(file_get_contents($sql_path));
  307. $sql_path = base_path('sqlupdates/v553.sql');
  308. DB::unprepared(file_get_contents($sql_path));
  309. $sql_path = base_path('sqlupdates/v554.sql');
  310. DB::unprepared(file_get_contents($sql_path));
  311. $sql_path = base_path('sqlupdates/v555.sql');
  312. DB::unprepared(file_get_contents($sql_path));
  313. $sql_path = base_path('sqlupdates/v556.sql');
  314. DB::unprepared(file_get_contents($sql_path));
  315. $sql_path = base_path('sqlupdates/v557.sql');
  316. DB::unprepared(file_get_contents($sql_path));
  317. $sql_path = base_path('sqlupdates/v60.sql');
  318. DB::unprepared(file_get_contents($sql_path));
  319. $sql_path = base_path('sqlupdates/v61.sql');
  320. DB::unprepared(file_get_contents($sql_path));
  321. $sql_path = base_path('sqlupdates/v611.sql');
  322. DB::unprepared(file_get_contents($sql_path));
  323. $sql_path = base_path('sqlupdates/v612.sql');
  324. DB::unprepared(file_get_contents($sql_path));
  325. return redirect()->route('update.step2');
  326. } else {
  327. Artisan::call('view:clear');
  328. Artisan::call('cache:clear');
  329. $previousRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.php');
  330. $newRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.txt');
  331. copy($newRouteServiceProvier, $previousRouteServiceProvier);
  332. return view('update.done');
  333. }
  334. }
  335. public function step2()
  336. {
  337. Artisan::call('view:clear');
  338. Artisan::call('cache:clear');
  339. $this->convertSellerIntoShop();
  340. $this->convertSellerIntoUser();
  341. $this->convertSellerPackageIntoShop();
  342. $this->convertTrasnalations();
  343. // $this->convertColorsName();
  344. $previousRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.php');
  345. $newRouteServiceProvier = base_path('app/Providers/RouteServiceProvider.txt');
  346. copy($newRouteServiceProvier, $previousRouteServiceProvier);
  347. return view('update.done');
  348. }
  349. public function convertSellerIntoShop()
  350. {
  351. $sellers = Seller::all();
  352. foreach ($sellers as $seller) {
  353. $shop = Shop::where('user_id', $seller->user_id)->first();
  354. if ($shop) {
  355. if (!$shop->rating) {
  356. $shop->rating = $seller->rating;
  357. $shop->num_of_reviews = $seller->num_of_reviews;
  358. }
  359. if (!$shop->num_of_sale) {
  360. $shop->num_of_sale = $seller->num_of_sale;
  361. }
  362. if (!$shop->seller_package_id) {
  363. $shop->seller_package_id = $seller->seller_package_id;
  364. $shop->product_upload_limit = $seller->product_upload_limit;
  365. $shop->package_invalid_at = $seller->invalid_at;
  366. }
  367. if ($shop->admin_to_pay == 0) {
  368. $shop->admin_to_pay = $seller->admin_to_pay;
  369. }
  370. $shop->verification_status = $seller->verification_status;
  371. $shop->verification_info = $seller->verification_info;
  372. $shop->cash_on_delivery_status = $seller->cash_on_delivery_status;
  373. if (!$shop->bank_name) {
  374. $shop->bank_name = $seller->bank_name;
  375. $shop->bank_acc_name = $seller->bank_acc_name;
  376. $shop->bank_acc_no = $seller->bank_acc_no;
  377. $shop->bank_routing_no = $seller->bank_routing_no;
  378. $shop->bank_payment_status = $seller->bank_payment_status;
  379. }
  380. $shop->save();
  381. }
  382. }
  383. }
  384. public function convertSellerIntoUser()
  385. {
  386. $seller_withdraw_requests = SellerWithdrawRequest::all();
  387. foreach ($seller_withdraw_requests as $seller_withdraw_request) {
  388. $seller = Seller::where('id', $seller_withdraw_request->user_id)->first();
  389. if ($seller) {
  390. $seller_withdraw_request->user_id = $seller->user_id;
  391. $seller_withdraw_request->save();
  392. }
  393. }
  394. }
  395. public function convertSellerPackageIntoShop()
  396. {
  397. if (Schema::hasTable('seller_packages')) {
  398. $shops = Shop::all();
  399. foreach ($shops as $shop) {
  400. $seller_package = SellerPackage::where('id', $shop->seller_package_id)->first();
  401. if ($seller_package) {
  402. $shop->product_upload_limit = $seller_package->product_upload_limit;
  403. $shop->save();
  404. }
  405. }
  406. }
  407. }
  408. public function convertTaxes()
  409. {
  410. $tax = Tax::first();
  411. foreach (Product::all() as $product) {
  412. $product_tax = new ProductTax;
  413. $product_tax->product_id = $product->id;
  414. $product_tax->tax_id = $tax->id;
  415. $product_tax->tax = $product->tax;
  416. $product_tax->tax_type = $product->tax_type;
  417. $product_tax->save();
  418. }
  419. }
  420. public function convertTrasnalations()
  421. {
  422. foreach (\App\Models\Translation::all() as $translation) {
  423. $lang_key = preg_replace('/[^A-Za-z0-9\_]/', '', str_replace(' ', '_', strtolower($translation->lang_key)));
  424. $translation->lang_key = $lang_key;
  425. $translation->save();
  426. }
  427. }
  428. public function convertColorsName()
  429. {
  430. foreach (\App\Models\Color::all() as $color) {
  431. $color->name = Str::replace(' ', '', $color->name);
  432. $color->save();
  433. }
  434. }
  435. public function convertRatingAndSales()
  436. {
  437. foreach (\App\Models\Seller::all() as $seller) {
  438. $total = 0;
  439. $rating = 0;
  440. $num_of_sale = 0;
  441. try {
  442. foreach ($seller->user->products as $seller_product) {
  443. $total += $seller_product->reviews->count();
  444. $rating += $seller_product->reviews->sum('rating');
  445. $num_of_sale += $seller_product->num_of_sale;
  446. }
  447. if ($total > 0) {
  448. $seller->rating = $rating / $total;
  449. $seller->num_of_reviews = $total;
  450. }
  451. $seller->num_of_sale = $num_of_sale;
  452. $seller->save();
  453. } catch (\Exception $e) {
  454. }
  455. }
  456. }
  457. }