Ver Fonte

Merge pull request #733 from visuddhinanda/laravel-migrate-wbw

Laravel migrate wbw
visuddhinanda há 4 anos atrás
pai
commit
0fb01d410c

+ 8 - 3
app/Http/Controllers/Controller.php

@@ -11,7 +11,7 @@ class Controller extends BaseController
 {
     use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
 
-	public function sendResponse($result,$message){
+	public function sendResponse($result,$message=""){
 		$response = [
 			'ok' => true,
 			'data'=>$result,
@@ -19,7 +19,9 @@ class Controller extends BaseController
 		];
 		return response()->json($response,200);
 	}
-
+    public function ok($result,$message=""){
+        return $this->sendResponse($result,$message);
+    }
 	public function sendError($error, $errorMessages = [], $code = 404){
 		$response = [
 			'ok' => false,
@@ -27,6 +29,9 @@ class Controller extends BaseController
 			'message'=> $error,
 		];
 		return response()->json($response,code);
-
 	}
+
+    public function error($error, $errorMessages, $code){
+        return $this->sendError($error, $errorMessages, $code);
+    }
 }

+ 166 - 0
app/Http/Controllers/DhammaTermController.php

@@ -0,0 +1,166 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\DhammaTerm;
+use Illuminate\Http\Request;
+
+class DhammaTermController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index(Request $request)
+    {
+        $result=false;
+		$indexCol = ['id','guid','word','word_en','meaning','other_meaning','note','language','channal','updated_at'];
+
+		switch ($request->get('view')) {
+			case 'user':
+				# code...
+                $userUid = $_COOKIE['user_uid'];
+                $search = $request->get('search');
+				$table = DhammaTerm::select($indexCol)
+									->where('owner', $userUid);
+				if(!empty($search)){
+					$table->where('word', 'like', $search."%")
+                          ->orWhere('word_en', 'like', $search."%")
+                          ->orWhere('meaning', 'like', "%".$search."%");
+				}
+				if(!empty($request->get('order')) && !empty($request->get('dir'))){
+					$table->orderBy($request->get('order'),$request->get('dir'));
+				}else{
+					$table->orderBy('updated_at','desc');
+				}
+				$count = $table->count();
+				if(!empty($request->get('limit'))){
+					$offset = 0;
+					if(!empty($request->get("offset"))){
+						$offset = $request->get("offset");
+					}
+					$table->skip($offset)->take($request->get('limit'));
+				}
+				$result = $table->get();
+				break;
+			case 'word':
+				$result = DhammaTerm::select($indexCol)
+									->where('word', $request->get("word"))
+									->orderBy('created_at','desc')
+									->get();
+				break;
+			default:
+				# code...
+				break;
+		}
+		if($result){
+			return $this->ok(["rows"=>$result,"count"=>$count]);
+		}else{
+			return $this->error("没有查询到数据");
+		}
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+                // validate
+        // read more on validation at http://laravel.com/docs/validation
+        $rules = array(
+            'word' => 'required',
+            'meaning' => 'required',
+            'language' => 'required'
+        );
+        $validator = Validator::make($request->all(), $rules);
+
+        // process the login
+        if ($validator->fails()) {
+            return $this->error($validator);
+        } else {
+            #查询重复的
+            $table = DhammaTerm::where('owner', $_COOKIE["user_uid"])
+                    ->where('word',$request->get("word"))
+                    ->where('tag',$request->get("tag"));
+            if($request->get("channel")){
+                $isDoesntExist = $table->where('channel',$request->get("channel"))
+                      ->doesntExist();
+            }else{
+                $isDoesntExist = $table->where('language',$request->get("language"))
+                    ->doesntExist();
+            }
+	
+            if($isDoesntExist){
+                #不存在插入数据
+                $term = new DhammaTerm;
+                $term->id=$snowflake->id();
+                $term->guid=Str::uuid();
+                $term->word=$request->get("word");
+                $term->meaning=$request->get("meaning");
+                $term->save();
+                return $this->ok($data);
+
+            }else{
+                return $this->error("word existed");
+            }
+            // store
+            /*
+            $data = $request->all();
+            $data['id'] = $snowflake->id();
+            $data['guid'] = Str::uuid();
+            DhammaTerm::create($data);
+            */
+            
+        }
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function show(DhammaTerm $dhammaTerm)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, DhammaTerm $dhammaTerm)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(DhammaTerm $dhammaTerm,Request $request)
+    {
+        //
+        $arrId = json_decode($request->get("id"),true) ;
+		$count = 0;
+		foreach ($arrId as $key => $id) {
+			# code...
+			$result = DhammaTerm::where('id', $id)
+							->where('owner', $_COOKIE["user_uid"])
+							->delete();
+            if($result){
+                $count++;
+            }
+		}
+		return $this->ok($count);
+    }
+}

+ 11 - 0
app/Models/DhammaTerm.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class DhammaTerm extends Model
+{
+    use HasFactory;
+}

+ 1 - 1
app/Providers/AppServiceProvider.php

@@ -19,7 +19,7 @@ class AppServiceProvider extends ServiceProvider
         //雪花算法
 		
 		$this->app->singleton('snowflake', function () {
-            return (new Snowflake())
+            return (new Snowflake(env('SNOWFLAKE_DATA_CENTER_ID'),env('SNOWFLAKE_WORKER_ID')))
                 ->setStartTimeStamp(strtotime(config('database.snowflake.start'))*1000)
                 ->setSequenceResolver(
                     new LaravelSequenceResolver($this->app->get('cache')->store()

+ 50 - 0
database/migrations/2022_02_02_103531_create_dhamma_terms_table.php

@@ -0,0 +1,50 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateDhammaTermsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('dhamma_terms', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+            $table->string('guid',36);
+
+            $table->string('word',1024)->index();
+            $table->string('word_en',1024)->index();
+            $table->string('meaning',1024)->index();
+            $table->string('other_meaning',1024)->nullable();
+            $table->text('note',1024)->nullable();
+            $table->string('tag',1024)->nullable();
+            $table->string('channal',36)->index()->nullable();
+            $table->string('language',16)->default('zh-hans');
+            $table->string('owner',36)->index();
+            $table->bigInteger('editor_id')->index();
+
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+
+			$table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+			$table->timestamp('deleted_at')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('dhamma_terms');
+    }
+}

+ 18 - 18
public/app/config.table.php

@@ -292,7 +292,7 @@ define("_SQLITE_DB_TERM_", "sqlite:" . __DIR__ . "/../tmp/user/dhammaterm.db");
 define("_SQLITE_TABLE_TERM_", "term");
 
 define("_PG_DB_TERM_", _PDO_DB_DSN_);
-define("_PG_TABLE_TERM_", "term");
+define("_PG_TABLE_TERM_", "dhamma_terms");
 
 # 协作
 define("_SQLITE_DB_USER_SHARE_", "sqlite:" . __DIR__ . "/../tmp/user/share.db3");
@@ -627,10 +627,7 @@ define("_TABLE_USER_OPERATION_LOG_", _PG_TABLE_USER_OPERATION_LOG_);
 
 
 //读取频繁 写入不频繁 
-# 用户账号
-#sqlite
-define("_FILE_DB_USERINFO_", _SQLITE_DB_USERINFO_);
-define("_TABLE_USER_INFO_", _SQLITE_TABLE_USER_INFO_);
+
 
 
 # 版本风格 
@@ -638,7 +635,6 @@ define("_TABLE_USER_INFO_", _SQLITE_TABLE_USER_INFO_);
 define("_FILE_DB_CHANNAL_", _PG_DB_CHANNAL_);
 define("_TABLE_CHANNEL_", _PG_TABLE_CHANNEL_);
 
-
 # 文章 文集
 
 define("_FILE_DB_USER_ARTICLE_", _PG_DB_USER_ARTICLE_);
@@ -646,11 +642,9 @@ define("_TABLE_ARTICLE_", _PG_TABLE_ARTICLE_);
 define("_TABLE_COLLECTION_", _PG_TABLE_COLLECTION_);
 define("_TABLE_ARTICLE_COLLECTION_", _PG_TABLE_ARTICLE_COLLECTION_);
 
-
-
 # 术语
-define("_FILE_DB_TERM_", _SQLITE_DB_TERM_);
-define("_TABLE_TERM_", _SQLITE_TABLE_TERM_);
+define("_FILE_DB_TERM_", _PG_DB_TERM_);
+define("_TABLE_TERM_", _PG_TABLE_TERM_);
 
 # 协作
 define("_FILE_DB_USER_SHARE_", _SQLITE_DB_USER_SHARE_);
@@ -666,24 +660,30 @@ define("_FILE_DB_FILEINDEX_", _SQLITE_DB_FILEINDEX_);
 define("_TABLE_FILEINDEX_", _SQLITE_TABLE_FILEINDEX_);
 define("_TABLE_FILEINDEX_POWER_", _SQLITE_TABLE_FILEINDEX_POWER_);
 
-# 课程
-define("_FILE_DB_COURSE_", _SQLITE_DB_COURSE_);
-define("_TABLE_COURSE_",_SQLITE_TABLE_COURSE_);
-define("_TABLE_LESSON_",_SQLITE_TABLE_LESSON_);
 
 # 用户自定义书
 define("_FILE_DB_USER_CUSTOM_BOOK_", _SQLITE_DB_USER_CUSTOM_BOOK_);
 define("_TABLE_CUSTOM_BOOK_", _SQLITE_TABLE_CUSTOM_BOOK_);
 define("_TABLE_CUSTOM_BOOK_SENT_", _SQLITE_TABLE_CUSTOM_BOOK_SENT_);
 
-# 逐词译和译文编辑消息 无需迁移数据
-define("_FILE_DB_MESSAGE_", _SQLITE_DB_MESSAGE_);
-define("_TABLE_MESSAGE_", _SQLITE_TABLE_MESSAGE_);
-
 #点赞
 define("_FILE_DB_LIKE_", _SQLITE_DB_LIKE_);
 define("_TABLE_LIKE_", _SQLITE_TABLE_LIKE_);
 
+# 课程
+define("_FILE_DB_COURSE_", _SQLITE_DB_COURSE_);
+define("_TABLE_COURSE_",_SQLITE_TABLE_COURSE_);
+define("_TABLE_LESSON_",_SQLITE_TABLE_LESSON_);
+
+
+# 用户账号
+define("_FILE_DB_USERINFO_", _SQLITE_DB_USERINFO_);
+define("_TABLE_USER_INFO_", _SQLITE_TABLE_USER_INFO_);
+
+# 逐词译和译文编辑消息 无需迁移数据
+define("_FILE_DB_MESSAGE_", _SQLITE_DB_MESSAGE_);
+define("_TABLE_MESSAGE_", _SQLITE_TABLE_MESSAGE_);
+
 
 # 用户字典统计数据 刷库 - 无需迁移数据
 define("_FILE_DB_USER_DICT_", _SQLITE_DB_USER_DICT_);

+ 3 - 3
public/app/term/get_term_index.php

@@ -23,15 +23,15 @@ if (isset($_POST["lang"])) {
 
 if (isset($_POST["word"])) {
     $word = $_POST["word"];
-    $query = "select word,meaning,language,owner,count(*) as co from term where word=? and language=? group by word,meaning order by co DESC";
+    $query = "SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where word=? and language=? group by word,meaning order by co DESC";
     $output["data"] = PDO_FetchAll($query, array($word, $lang));
 } else {
-    $query = "select * from (select word,meaning,language,owner,count(*) as co from term where language=? group by word,meaning order by co DESC) where 1 group by word";
+    $query = "SELECT * from (SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where language=? group by word,meaning order by co DESC)  group by word";
     $output["data"] = PDO_FetchAll($query, array($lang));
     $pos = mb_strpos($lang, "-", 0, "UTF-8");
     if ($pos) {
         $lang_family = mb_substr($lang, 0, $pos, "UTF-8");
-        $query = "select * from (select word,meaning,language,owner,count(*) as co from term where language like ? group by word,meaning order by co DESC) where 1 group by word";
+        $query = "SELECT * from (SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where language like ? group by word,meaning order by co DESC)  group by word";
         $otherlang = PDO_FetchAll($query, array($lang_family . "%"));
         foreach ($otherlang as $key => $value) {
             $output["data"][] = $value;

+ 80 - 0
public/app/term/my_dict_list-beta.php

@@ -0,0 +1,80 @@
+<?php
+require_once '../studio/index_head.php';
+?>
+<body id="file_list_body"  onLoad="my_term_onload()">
+	<script src="../channal/channal.js"></script>
+
+    <script src="../term/my_term.js"></script>
+    <script src="../term/term_edit_dlg.js"></script>
+	<link type="text/css" rel="stylesheet" href="../term/term_edit_dlg.css"/>
+	<script >
+	var gCurrPage="term";
+	</script>
+
+	<style>
+	#term {
+		background-color: var(--btn-border-color);
+
+	}
+	#term:hover{
+		background-color: var(--btn-border-color);
+		color: var(--btn-color);
+		cursor:auto;
+    }
+    #word_list{
+        width:unset;
+    }
+	#setting_user_dict_nav{
+		width:95%;
+		display:inline-flex;
+		justify-content: space-between;
+}
+	}
+	</style>
+
+<?php
+require_once '../studio/index_tool_bar.php';
+?>
+
+	<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">
+		<div id="word_list"  class="file_list_block">
+
+		<div class="tool_bar">
+	<div>
+	<?php echo $_local->gui->userdict; ?>
+	</div>
+
+	<div>
+		<span class="icon_btn_div">
+			<span class="icon_btn_tip"><?php echo $_local->gui->add; ?></span>
+			<button id="file_add" type="button" class="icon_btn" title=" ">
+				<a href="../course/my_channal_new.php">
+				<svg class="icon">
+					<use xlink:href="../studio/svg/icon.svg#ic_add_circle"></use>
+				</svg>
+				</a>
+			</button>
+		</span>
+
+		<span class="icon_btn_div">
+			<span class="icon_btn_tip"><?php echo $_local->gui->recycle_bin; ?></span>
+			<button id="to_recycle" type="button" class="icon_btn" title="delete">
+				<svg class="icon">
+					<use xlink:href="../studio/svg/icon.svg#ic_delete"></use>
+				</svg>
+			</button>
+		</span>
+	</div>
+
+</div>
+<script src="../../node_modules/gridjs/dist/gridjs.umd.js"></script>
+<link
+      href="../../node_modules/gridjs/dist/theme/mermaid.min.css"
+      rel="stylesheet"
+    />
+
+<div id="userfilelist"></div>
+<script  type="module" src="my_dict_list.js"></script>
+<?php
+require_once '../studio/index_foot.php';
+?>

+ 129 - 0
public/app/term/my_dict_list.js

@@ -0,0 +1,129 @@
+import { Grid, h } from "../../node_modules/gridjs/dist/gridjs.module.js";
+export var _rowSelected =   new Array();
+const grid = new gridjs.Grid({
+	sort: {
+		multiColumn: false,
+		server: {
+		  url: (prev, columns) => {
+		   if (!columns.length) return prev;
+		   
+		   const col = columns[0];
+		   const dir = col.direction === 1 ? 'asc' : 'desc';
+		   let colName = ['Sel','id','guid', 'word','word_en','meaning','other_meaning','updated_at'][col.index];
+		   
+		   return `${prev}&order=${colName}&dir=${dir}`;
+		 }
+		}
+	  },
+	columns: [
+		{ 
+			name: 'Sel',
+			hidden: false,
+			sort: false,
+			formatter: (cell, row) => {
+			return h('input', {
+				type:'checkbox',
+				className: 'py-2 mb-4 px-4 border',
+				id:"cb-"+row.cells[1].data,
+				onClick: () =>{
+					let id = row.cells[1].data;
+					if(document.querySelector("#cb-"+id).checked){
+						_rowSelected.push(id);
+						console.log("checked",_rowSelected);
+					}else{
+						_rowSelected.splice(_rowSelected.findIndex(item => item ===id),1);
+						console.log("remove",_rowSelected);
+					}
+				} 
+			}, '');
+			}
+      	},
+        {
+			name: 'id',
+			hidden: true
+		},
+		{
+			name: 'guid',
+			hidden: true
+		},
+		'word',
+		{
+			name:'word_en',
+			sort: false,
+            hidden: true
+		},
+		{
+			name:'meaning',
+			sort: false,
+		},
+		{
+			name:'other_meaning',
+			sort: false,
+		},
+        'updated_at',
+		{ 
+			name: 'Actions',
+			sort: false,
+			hidden:false,
+			formatter: (cell, row) => {
+			return h('button', {
+				className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
+				onClick: () =>{
+                    let id = row.cells[2].data;
+					term_edit_dlg_open(id);
+				} 
+			}, 'Edit');
+			}
+      	}
+	],
+	server: {
+		url: '/api/v2/terms?view=user',
+		then: data => data.data.rows.map(card => [null,card.id,card.guid,card.word, card.word_en, card.meaning, card.other_meaning, card.updated_at,null]),
+		total: data => data.data.count
+	  },
+	pagination: {
+		enabled: true,
+		limit:30,
+		server: {
+			url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
+		  }
+	},
+	search: {
+		server: {
+		  url: (prev, keyword) => `${prev}&search=${keyword}`
+		}
+	  },
+	resizable: true,
+  }).render(document.getElementById("userfilelist"));
+
+//grid.on('rowClick', (...args) => console.log('row: ' + JSON.stringify(args), args));
+//grid.on('cellClick', (...args) => console.log(cell,args));
+
+document.querySelector("#to_recycle").onclick = function(){
+	if(_rowSelected.length>0){
+		if(confirm(`删除${_rowSelected.length}个单词,此操作不能恢复。`)){
+        $.ajax(
+        {
+            url: "/api/v2/terms/0",
+            type: 'DELETE',
+            data: {
+                id:JSON.stringify(_rowSelected),
+                "_token": 'token',
+            },
+            success: function (response){
+                if(response.ok){
+                    grid.forceRender();
+                    alert('delete ' + response.data + 'word ok');
+                }else{
+                    alert(`delete error `+response.message);
+                }
+            },
+            error: function (error) {
+                console.log(error);
+            }
+        });
+
+		}
+
+	}
+}

+ 4 - 4
public/app/term/my_dict_list.php

@@ -78,9 +78,9 @@ $iOnePage = 300;
 
 PDO_Connect(_FILE_DB_TERM_);
 
-$query = "select count(*) as co  from term where owner= ? ";
+$query = "SELECT count(*) as co  from "._TABLE_TERM_." where owner= ? ";
 
-$allWord = PDO_FetchOne($query, array($_COOKIE["userid"]));
+$allWord = PDO_FetchOne($query, array($_COOKIE["user_uid"]));
 $iCountWords = $allWord;
 
 if ($iCountWords == 0) {
@@ -93,8 +93,8 @@ if ($iCountWords == 0) {
     }
     $begin = $iCurrPage * $iOnePage;
 
-    $query = "select *  from term where owner= ? ";
-    $allWords = PDO_FetchAll($query, array($_COOKIE["userid"]));
+    $query = "SELECT *  from "._TABLE_TERM_." where owner= ? ";
+    $allWords = PDO_FetchAll($query, array($_COOKIE["user_uid"]));
 
     echo '<div id="setting_user_dict_nav">';
 

+ 1 - 1
public/app/term/new.php

@@ -9,7 +9,7 @@ require_once '../ucenter/function.php';
 PDO_Connect(_FILE_DB_TERM_);
 $userInfo = new UserInfo();
 
-$query = "select word,meaning , owner from term where 1  order by create_time DESC limit 0,4";
+$query = "SELECT word,meaning , owner from "._TABLE_TERM_."  order by create_time DESC limit 4";
 $Fetch = PDO_FetchAll($query);
 
 foreach ($Fetch as $row) {

+ 40 - 18
public/app/term/term.php

@@ -5,6 +5,8 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/load_lang.php';
 require_once '../public/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 //is login
 if (isset($_COOKIE["username"])) {
@@ -41,7 +43,7 @@ if (isset($_GET["username"])) {
 }
 
 global $PDO;
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect( _FILE_DB_TERM_);
 switch ($op) {
     case "pre": //预查询
         {
@@ -49,10 +51,10 @@ switch ($op) {
 				echo json_encode(array(), JSON_UNESCAPED_UNICODE);
             	break;
 			}
-            $query = "SELECT word,meaning from term where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
+            $query = "SELECT word,meaning from "._TABLE_TERM_." where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
             $Fetch = PDO_FetchAll($query);
             if (count($Fetch) < 3) {
-                $query = "SELECT word,meaning from term where \"word_en\" like " . $PDO->quote('%' . $word . '%') . " OR \"word\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
+                $query = "SELECT word,meaning from "._TABLE_TERM_." where \"word_en\" like " . $PDO->quote('%' . $word . '%') . " OR \"word\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
                 $Fetch2 = PDO_FetchAll($query);
                 //去掉重复的
                 foreach ($Fetch2 as $onerow) {
@@ -68,12 +70,12 @@ switch ($op) {
                     }
                 }
                 if (count($Fetch) < 8) {
-                    $query = "SELECT word,meaning from term where \"meaning\" like " . $PDO->quote($word . '%') . " OR \"other_meaning\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
+                    $query = "SELECT word,meaning from "._TABLE_TERM_." where \"meaning\" like " . $PDO->quote($word . '%') . " OR \"other_meaning\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
                     $Fetch3 = PDO_FetchAll($query);
 
                     $Fetch = array_merge($Fetch, $Fetch3);
                     if (count($Fetch) < 8) {
-                        $query = "SELECT word,meaning from term where \"meaning\" like " . $PDO->quote('%' . $word . '%') . " OR \"other_meaning\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
+                        $query = "SELECT word,meaning from "._TABLE_TERM_." where \"meaning\" like " . $PDO->quote('%' . $word . '%') . " OR \"other_meaning\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
                         $Fetch4 = PDO_FetchAll($query);
                         //去掉重复的
                         foreach ($Fetch4 as $onerow) {
@@ -96,7 +98,7 @@ switch ($op) {
         }
     case "my":
         {
-            $query = "select guid,word,meaning,other_meaning,language from term  where owner= ? ";
+            $query = "select guid,word,meaning,other_meaning,language from "._TABLE_TERM_."  where owner= ? ";
             $Fetch = PDO_FetchAll($query, array($_COOKIE["userid"]));
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -108,7 +110,7 @@ switch ($op) {
         }
     case "allpali":
         {
-            $query = "select word from term  where 1 group by word";
+            $query = "select word from "._TABLE_TERM_."  where 1 group by word";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -118,7 +120,7 @@ switch ($op) {
         }
     case "allmean":
         {
-            $query = "select meaning from term  where \"word\" = " . $PDO->quote($word) . " group by meaning";
+            $query = "select meaning from "._TABLE_TERM_."  where \"word\" = " . $PDO->quote($word) . " group by meaning";
             $Fetch = PDO_FetchAll($query);
             foreach ($Fetch as $one) {
                 echo "<a>" . $one["meaning"] . "</a> ";
@@ -130,7 +132,7 @@ switch ($op) {
         {
             if (isset($_GET["id"])) {
                 $id = $_GET["id"];
-                $query = "select * from term  where \"guid\" = " . $PDO->quote($id);
+                $query = "select * from "._TABLE_TERM_."  where \"guid\" = " . $PDO->quote($id);
                 $Fetch = PDO_FetchAll($query);
                 echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
             } else {
@@ -149,7 +151,7 @@ switch ($op) {
             echo "<div class='pali'>{$word}</div>";
             //查本人数据
             echo "<div></div>"; //My Term
-            $query = "select * from term  where word = ? AND  owner = ? limit 0,30";
+            $query = "select * from "._TABLE_TERM_."  where word = ? AND  owner = ? limit 30";
             $Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -235,7 +237,7 @@ switch ($op) {
             echo "</div>";
 
             //查他人数据
-            $query = "SELECT * FROM term  WHERE word = ? AND owner <> ? LIMIT 0,30";
+            $query = "SELECT * FROM "._TABLE_TERM_."  WHERE word = ? AND owner <> ? LIMIT 30";
 
             $Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
             $iFetch = count($Fetch);
@@ -262,23 +264,43 @@ switch ($op) {
         }
     case "copy": //拷贝到我的字典
         {
-            $query = "select * from term  where \"guid\" = " . $PDO->quote($_GET["wordid"]);
+            $query = "select * from "._TABLE_TERM_."  where \"guid\" = " . $PDO->quote($_GET["wordid"]);
 
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
                 /* 开始一个事务,关闭自动提交 */
                 $PDO->beginTransaction();
-                $query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
+                $query = "INSERT INTO "._TABLE_TERM_." 
+                (
+                    'id',
+                    'guid',
+                    'word',
+                    'word_en',
+                    'meaning',
+                    'other_meaning',
+                    'note',
+                    'tag',
+                    'owner',
+                    'editor_id',
+                    'create_time',
+                    'update_time',
+                    ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
                 $stmt = $PDO->prepare($query);
                 {
-                    $stmt->execute(array(UUID::v4,
+                    $stmt->execute(array(
+                        $snowflake->id(),
+                        UUID::v4,
                         $Fetch[0]["word"],
                         $Fetch[0]["word_en"],
                         $Fetch[0]["meaning"],
                         $Fetch[0]["other_meaning"],
                         $Fetch[0]["note"],
                         $Fetch[0]["tag"],
+                        $_COOKIE['user_uid'],
+                        $_COOKIE['user_id'],
+                        mTime(),
+                        mTime()
                     ));
                 }
                 /* 提交更改 */
@@ -301,7 +323,7 @@ switch ($op) {
                 $authors = str_getcsv($_POST["authors"]);
             }
             $queryLang = $currLanguage . "%";
-            $query = "SELECT * from term  where \"word\" in {$words} AND language like ?  limit 0,1000";
+            $query = "SELECT * from "._TABLE_TERM_."  where \"word\" in {$words} AND language like ?  limit 1000";
             $Fetch = PDO_FetchAll($query, array($queryLang));
             $iFetch = count($Fetch);
             echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
@@ -310,7 +332,7 @@ switch ($op) {
     case "sync":
         {
             $time = $_GET["time"];
-            $query = "SELECT guid,modify_time from term  where receive_time>'{$time}'   limit 0,1000";
+            $query = "SELECT guid,modify_time from "._TABLE_TERM_."  where receive_time>'{$time}'   limit 1000";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
@@ -320,9 +342,9 @@ switch ($op) {
         {
             $Fetch = array();
             if (isset($guid)) {
-                $query = "select * from term  where \"guid\" = '{$guid}'";
+                $query = "select * from "._TABLE_TERM_."  where \"guid\" = '{$guid}'";
             } else if (isset($word)) {
-                $query = "select * from term  where \"word\" = '{$word}'";
+                $query = "select * from "._TABLE_TERM_."  where \"word\" = '{$word}'";
             } else {
                 echo "[]";
                 return;

+ 4 - 4
public/app/term/term_channel_get.php

@@ -10,7 +10,7 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 require_once '../channal/function.php';
 
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect(_FILE_DB_TERM_);
 
 $output = array();
 if (isset($_POST["words"])) {
@@ -30,7 +30,7 @@ if (isset($_POST["words"])) {
         /*  创建一个填充了和params相同数量占位符的字符串 */
         $place_holders = implode(',', array_fill(0, count($channal), '?'));
         $owner_holders = implode(',', array_fill(0, count($channal_owner), '?'));
-        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM term WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
+        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM "._TABLE_TERM_." WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
         foreach ($channal_owner as $key => $value) {
             # code...
             $channal[] = $key;
@@ -82,9 +82,9 @@ if (isset($_POST["words"])) {
             }
 
             if ($otherCase == "") {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? ";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? ";
             } else {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? AND ( $otherCase )";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? AND ( $otherCase )";
             }
 
             $fetch = PDO_FetchAll($query, $parm);

+ 4 - 4
public/app/term/term_get.php

@@ -10,7 +10,7 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 require_once '../channal/function.php';
 
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect(_FILE_DB_TERM_);
 
 $output = array();
 if (isset($_POST["words"])) {
@@ -29,7 +29,7 @@ if (isset($_POST["words"])) {
         /*  创建一个填充了和params相同数量占位符的字符串 */
         $place_holders = implode(',', array_fill(0, count($channal), '?'));
         $owner_holders = implode(',', array_fill(0, count($channal_owner), '?'));
-        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM term WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
+        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM "._TABLE_TERM_." WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
         foreach ($channal_owner as $key => $value) {
             # code...
             $channal[] = $key;
@@ -80,9 +80,9 @@ if (isset($_POST["words"])) {
             }
 
             if ($otherCase == "") {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? ";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? ";
             } else {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? AND ( $otherCase )";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? AND ( $otherCase )";
             }
 
             $fetch = PDO_FetchAll($query, $parm);

+ 3 - 3
public/app/term/term_get_id.php

@@ -8,16 +8,16 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../ucenter/function.php';
 
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect( _FILE_DB_TERM_);
 
 $fetch = array();
 if (isset($_POST["id"])) {
-    $query = "SELECT * FROM term WHERE guid = ? ";
+    $query = "SELECT * FROM "._TABLE_TERM_." WHERE guid = ? ";
 
     $fetch = PDO_FetchRow($query, array($_POST["id"]));
-    $userinfo = new UserInfo();
     if ($fetch) {
         # code...
+        $userinfo = new UserInfo();
         $fetch["user"] = $userinfo->getName($fetch["owner"]);
     }
 }

+ 55 - 34
public/app/term/term_post.php

@@ -7,6 +7,8 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once "../redis/function.php";
 require_once "../channal/function.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $redis = redis_connect();
 
@@ -20,7 +22,7 @@ if (isset($_COOKIE["userid"]) == false) {
 
 
 $respond = array("status" => 0, "message" => "");
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect( _FILE_DB_TERM_);
 
 
 
@@ -28,7 +30,7 @@ if ($_POST["id"] != "") {
 	#更新
 	#先查询是否有权限
 	#是否这个术语的作者
-	$query = "SELECT id,channal,owner from term where guid= ? ";
+	$query = "SELECT id,channal,owner from "._TABLE_TERM_." where guid= ? ";
 	$stmt = $PDO->prepare($query);
 	$stmt->execute(array($_POST["id"]));
 	if ($stmt) {
@@ -54,7 +56,7 @@ if ($_POST["id"] != "") {
 			exit;				
 		}
 	}
-    $query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? , receive_time= ?, modify_time= ?   where guid= ? ";
+    $query = "UPDATE "._TABLE_TERM_." SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? ,  modify_time= ? , updated_at = now()  where guid= ? ";
 	$stmt = @PDO_Execute($query, 
 						array($_POST["mean"],
         					  $_POST["mean2"],
@@ -63,7 +65,6 @@ if ($_POST["id"] != "") {
         					  $_POST["language"],
         					  $_POST["note"],
         					  mTime(),
-        					  mTime(),
         					  $_POST["id"],
     ));
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
@@ -107,11 +108,11 @@ if ($_POST["id"] != "") {
 	}
 	#先查询是否有重复数据
 	if($_POST["channal"]==""){
-		$query = "SELECT id from term where word= ? and  language=? and tag=? and owner = ? ";
+		$query = "SELECT id from "._TABLE_TERM_." where word= ? and  language=? and tag=? and owner = ? ";
 		$stmt = $PDO->prepare($query);
 		$stmt->execute(array($_POST["word"],$_POST["language"],$_POST["tag"],$_COOKIE["userid"]));
 	}else{
-		$query = "SELECT id from term where word= ? and channal=?  and tag=? and owner = ? ";
+		$query = "SELECT id from "._TABLE_TERM_." where word= ? and channal=?  and tag=? and owner = ? ";
 		$stmt = $PDO->prepare($query);
 		$stmt->execute(array($_POST["word"],$_POST["channal"],$_POST["tag"],$_COOKIE["userid"]));
 	}
@@ -125,22 +126,40 @@ if ($_POST["id"] != "") {
 			exit;
 		}
 	}
-    $parm[] = UUID::v4();
-    $parm[] = $_POST["word"];
-    $parm[] = pali2english($_POST["word"]);
-    $parm[] = $_POST["mean"];
-    $parm[] = $_POST["mean2"];
-    $parm[] = $_POST["tag"];
-    $parm[] = $_POST["channal"];
-    $parm[] = $_POST["language"];
-    $parm[] = $_POST["note"];
-    $parm[] = $_COOKIE["userid"];
-    $parm[] = 0;
-    $parm[] = mTime();
-    $parm[] = mTime();
-    $parm[] = mTime();
-    $query = "INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
-	VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
+    $parm = [
+        $snowflake->id(),
+        UUID::v4(),
+        $_POST["word"],
+        pali2english($_POST["word"]),
+        $_POST["mean"],
+        $_POST["mean2"],
+        $_POST["tag"],
+        $_POST["channal"],
+        $_POST["language"],
+        $_POST["note"],
+        $_COOKIE["user_uid"],
+        $_COOKIE["user_id"],
+        mTime(),
+        mTime()
+        ];
+    $query = "INSERT INTO "._TABLE_TERM_." 
+    (
+        id, 
+        guid, 
+        word, 
+        word_en, 
+        meaning, 
+        other_meaning, 
+        tag, 
+        channal, 
+        language,
+        note,
+        owner,
+        editor_id,
+        create_time,
+        modify_time
+    )
+	VALUES (?, ? , ?, ?, ?, ?, ?, ?, ?, ? , ?, ?, ?, ?) ";
     $stmt = @PDO_Execute($query, $parm);
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
@@ -149,17 +168,19 @@ if ($_POST["id"] != "") {
     } else {
         $respond['status'] = 0;
         $respond['message'] = $_POST["word"];
-        $respond['data'] = ["guid"=>$parm[0],
-							"word"=>$parm[1],
-							"word_en"=>$parm[2],
-							"meaning"=>$parm[3],
-							"other_meaning"=>$parm[4],
-							"tag"=>$parm[5],
-							"channal"=>$parm[6],
-							"language"=>$parm[7],
-							"note"=>$parm[8],
-							"owner"=>$parm[9]
-						];
+        $respond['data'] = [
+            "id"=>$parm[0],
+            "guid"=>$parm[2],
+			"word"=>$parm[3],
+			"word_en"=>$parm[3],
+			"meaning"=>$parm[4],
+			"other_meaning"=>$parm[5],
+			"tag"=>$parm[6],
+			"channal"=>$parm[7],
+			"language"=>$parm[8],
+			"note"=>$parm[9],
+			"owner"=>$parm[10]
+			];
 
     }
 }
@@ -168,7 +189,7 @@ if ($_POST["id"] != "") {
 	if ($redis != false) {
 		{
 			# code...
-			$query = "SELECT id,word,meaning,other_meaning,note,owner,language from term where word = ? ";
+			$query = "SELECT id,word,meaning,other_meaning,note,owner,language from "._TABLE_TERM_." where word = ? ";
 			$stmt = $PDO->prepare($query);
 			$stmt->execute(array($_POST["word"]));
 			if ($stmt) {

+ 3 - 3
public/app/term/update_analytics.php

@@ -5,15 +5,15 @@ require_once '../public/load_lang.php';
 require_once '../public/function.php';
 
 global $PDO;
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect(_FILE_DB_TERM_);
 
 echo "Day Index,创建,更新\n";
 $end = strtotime("now");
 $begin = strtotime("-1 day");
 for ($i = 0; $i < 100; $i++) {
-    $query = "select count(*) from term where \"create_time\" > " . $PDO->quote($begin) . " AND \"create_time\" < " . $PDO->quote($end);
+    $query = "SELECT count(*) from "._TABLE_TERM_." where \"create_time\" > " . $PDO->quote($begin) . " AND \"create_time\" < " . $PDO->quote($end);
     $create = PDO_FetchOne($query);
-    $query = "select count(*) from term where modify_time <> create_time AND \"modify_time\" > " . $PDO->quote($begin) . " AND \"modify_time\" < " . $PDO->quote($end);
+    $query = "SELECT count(*) from "._TABLE_TERM_." where modify_time <> create_time AND \"modify_time\" > " . $PDO->quote($begin) . " AND \"modify_time\" < " . $PDO->quote($end);
     $modify = PDO_FetchOne($query);
     echo date("m/d/Y", $begin) . ',' . $create . "," . $modify . "\n";
     $end = $begin;

Diff do ficheiro suprimidas por serem muito extensas
+ 19 - 0
public/app/ucenter/jquery_jwt_example.html


+ 17 - 0
public/db/sqlite/dhammaterm/term.sql

@@ -0,0 +1,17 @@
+CREATE TABLE dhammaterm (
+    id            INTEGER   PRIMARY KEY AUTOINCREMENT,
+    guid          TEXT (36),
+    word          TEXT,
+    word_en       TEXT,
+    meaning       TEXT,
+    other_meaning TEXT,
+    note          TEXT,
+    tag           TEXT,
+    create_time   INTEGER,
+    owner         TEXT,
+    hit           INTEGER   DEFAULT (0),
+    language      CHAR (8),
+    receive_time  INTEGER,
+    modify_time   INTEGER,
+    channal       TEXT
+);

+ 2 - 0
routes/api.php

@@ -3,6 +3,7 @@
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Route;
 use App\Http\Controllers\WbwTemplateController;
+use App\Http\Controllers\DhammaTermController;
 /*
 |--------------------------------------------------------------------------
 | API Routes
@@ -20,4 +21,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
 
 Route::group(['prefix' => 'v2'],function(){
 	Route::apiResource('wbw_templates',WbwTemplateController::class);
+	Route::apiResource('terms',DhammaTermController::class);
 });

+ 8 - 0
v1/scripts/install3.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+date
+
+php ./migrations/20220202172100_dhamma_terms_copy.php
+
+
+date

+ 190 - 0
v1/scripts/migrations/20220202172100_dhamma_terms_copy.php

@@ -0,0 +1,190 @@
+<?php
+/*
+迁移  article 库
+从旧数据表中提取数据插入到新的表
+插入时用uuid判断是否曾经插入
+曾经插入就不插入了
+*/
+require_once __DIR__."/../../../public/app/config.php";
+require_once __DIR__."/../../../public/app/public/snowflakeid.php";
+
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+$start = time();
+# 雪花id
+$snowflake = new SnowFlakeId();
+
+$fpError = fopen(__DIR__.'/log/'.basename($_SERVER['PHP_SELF'],'.php').".err.data.csv",'w');
+
+#user info
+$user_db=_FILE_DB_USERINFO_;#user数据库
+$user_table=_TABLE_USER_INFO_;#user表名
+
+# 
+$src_db = _SQLITE_DB_TERM_;#源数据库
+$src_table = _SQLITE_TABLE_TERM_;#源表名
+
+$dest_db = _PG_DB_TERM_;#目标数据库
+$dest_table = _PG_TABLE_TERM_;#目标表名
+
+fwrite(STDOUT,"migarate dhammaterm".PHP_EOL);
+#打开user数据库
+$PDO_USER = new PDO($user_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_USER->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open user table".PHP_EOL);
+
+#打开源数据库
+$PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open src table".PHP_EOL);
+
+#打开目标数据库
+$PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open dest table".PHP_EOL);
+
+$queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									guid,
+									word,
+									word_en,
+									meaning,
+									other_meaning,
+									note,
+									tag,
+									channal,
+									language,
+									owner,
+									editor_id,
+									create_time,
+									modify_time,
+									updated_at,
+									created_at) 
+									VALUES (? , ? , ? , ?, ? , ? ,? , ? , ? , ? , ? , ? , ?,? ,?,?)";
+$stmtDEST = $PDO_DEST->prepare($queryInsert);
+
+$commitData = [];
+$allInsertCount = 0;
+$allSrcCount = 0;
+$count = 0;
+
+#从user数据表中读取
+$query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    if($srcData["owner"]=='visuddhinanda'){
+		$srcData["owner"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+    if($srcData["owner"]=='test7'){
+		$srcData["owner"] = '6bd2f4d7-d970-419c-8ee5-f4bac42f4bc1';
+	}
+    if($srcData["owner"]=='Dhammadassi'){
+		$srcData["owner"] = 'd8538ebd-d369-4777-b99a-3ccb1aff8bfc';
+	}
+    if($srcData["owner"]=='pannava'){
+		$srcData["owner"] = '4db550c4-bc1b-43f2-a518-2740cb478f37';
+	}
+    if($srcData["owner"]=='NST'){
+		$srcData["owner"] = '5c23e629-56a3-48e9-97c7-2af73b59c3b9';
+	}
+    if($srcData["owner"]=='viranyani'){
+		$srcData["owner"] = 'C1AB2ABF-EAA8-4EEF-B4D9-3854321852B4';
+	}
+    if($srcData["owner"]=='test6'){
+		$srcData["owner"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["owner"]=='test28'){
+		$srcData["owner"] = 'df0ad9bc-c0cd-4cd9-af05-e43d23ed57f0';
+	}
+	if($srcData["owner"]=='290fd808-2f46-4b8c-b300-0367badd67ed'){
+		$srcData["owner"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["owner"]=='BA837178-9ABD-4DD4-96A0-D2C21B756DC4'){
+		$srcData["owner"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+	$stmtUser->execute(array($srcData["owner"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["owner"]}".PHP_EOL);
+		continue;
+	}
+	if(strlen($srcData["owner"])>36){
+		fwrite(STDERR,time().",error,user id too long {$srcData["owner"]}".PHP_EOL);
+		continue;	
+	}
+    if(empty($srcData["word"])){
+		fwrite(STDERR,time().",error,word is empty {$srcData["id"]}".PHP_EOL);
+		continue;	
+	}
+    if(empty($srcData["language"]) ){
+        $srcData["language"]='zh-hans';
+    }
+
+    if($srcData["create_time"] < 15987088320){
+        $srcData["create_time"] *= 1000;
+    }
+    if($srcData["modify_time"] < 15987088320){
+        $srcData["modify_time"] *= 1000;
+    }
+	//查询是否已经插入
+	$queryExsit = "SELECT id  FROM ".$dest_table." WHERE guid = ? ";
+	$getExist = $PDO_DEST->prepare($queryExsit);
+	$getExist->execute(array($srcData["id"]));
+	$exist = $getExist->fetch(PDO::FETCH_ASSOC);
+	if($exist){
+		continue;
+	}
+	#插入目标表
+	$created_at = date("Y-m-d H:i:s.",$srcData["create_time"]/1000).($srcData["create_time"]%1000)." UTC";
+	$updated_at = date("Y-m-d H:i:s.",$srcData["modify_time"]/1000).($srcData["modify_time"]%1000)." UTC";
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["guid"],
+			$srcData["word"],
+			$srcData["word_en"],
+			$srcData["meaning"],
+			$srcData["other_meaning"],
+			$srcData["note"],
+			$srcData["tag"],
+			$srcData["channal"],
+			$srcData["language"],
+			$srcData["owner"],
+            $userId["id"],
+			$srcData["create_time"],
+			$srcData["modify_time"],
+			$created_at,
+			$updated_at
+		);
+	$stmtDEST->execute($commitData);
+
+	$count++;	
+	$allInsertCount++;
+
+
+	if($count ==10000){
+		#10000行输出log 一次
+		echo "finished $count".PHP_EOL;
+		$count=0;
+	}	
+}
+
+fwrite(STDOUT,"insert done $allInsertCount in $allSrcCount ".PHP_EOL) ;
+fwrite(STDOUT, "all done in ".(time()-$start)."s".PHP_EOL);
+
+fclose($fpError);
+
+
+
+

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff