SettingSeeder.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. use Illuminate\Database\Seeder;
  3. class SettingSeeder extends Seeder
  4. {
  5. protected $oldTable = 'sz_yi_sysset';
  6. protected $newTable = 'yz_setting';
  7. /**
  8. * Run the database seeds.
  9. *
  10. * @return void
  11. */
  12. public function run()
  13. {
  14. Log::info('调试-SettingSeeder');
  15. return;
  16. if (!Schema::hasTable($this->oldTable)) {
  17. echo $this->oldTable." 不存在 跳过\n";
  18. return;
  19. }
  20. $newList = \Illuminate\Support\Facades\DB::table($this->newTable)->get();
  21. if($newList->isNotEmpty()){
  22. echo "yz_setting 已经有数据了跳过\n";
  23. return ;
  24. }
  25. $list = \Illuminate\Support\Facades\DB::table($this->oldTable)->get();
  26. if($list){
  27. foreach ($list as $v){
  28. Setting::$uniqueAccountId = $v['uniacid'];
  29. if($v['sets']) {
  30. $sets = @unserialize($this->_fixData($v['sets']));
  31. if($sets) {
  32. foreach ($sets as $k1 => $v1) {
  33. Setting::set('shop.' . $k1, $v1);
  34. }
  35. }
  36. }
  37. if($v['plugins']) {
  38. $plugins = @unserialize($this->_fixData($v['plugins']));
  39. if($plugins) {
  40. foreach ($plugins as $k2 => $v2) {
  41. if(is_array($v2)) {
  42. foreach ($v2 as $kk2 => $vv2) {
  43. Setting::set(($k2 ? : 'plugin') . '.' . $kk2, $vv2);
  44. }
  45. }else{
  46. Setting::set('plugin.' . $k2, $v2);
  47. }
  48. }
  49. }
  50. }
  51. if($v['sec']) {
  52. $sec = @unserialize($this->_fixData($v['sec']));
  53. if($sec) {
  54. foreach ($sec as $k3 => $v3) {
  55. Setting::set('pay.' . $k3, $v3);
  56. }
  57. }
  58. }
  59. echo "完成:uniacid:".$v['uniacid'] ."\n";
  60. }
  61. }
  62. }
  63. private function _fixData($badData)
  64. {
  65. $data = preg_replace_callback(
  66. '/(?<=^|\{|;)s:(\d+):\"(.*?)\";(?=[asbdiO]\:\d|N;|\}|$)/s',
  67. function($m){
  68. return 's:' . mb_strlen($m[2]) . ':"' . $m[2] . '";';
  69. },
  70. $badData
  71. );
  72. return $data;
  73. }
  74. }