فهرست منبع

Merge branch 'laravel-migrate-wbw' into laravel

visuddhinanda@gmail.com 4 سال پیش
والد
کامیت
03d64dd9f7
41فایلهای تغییر یافته به همراه1104 افزوده شده و 338 حذف شده
  1. 11 0
      app/Models/FileIndex.php
  2. 11 0
      app/Models/GroupInfo.php
  3. 11 0
      app/Models/GroupMember.php
  4. 41 0
      database/migrations/2022_02_05_020339_create_group_infos_table.php
  5. 43 0
      database/migrations/2022_02_05_024244_create_group_members_table.php
  6. 57 0
      database/migrations/2022_02_06_075148_create_file_indices_table.php
  7. 3 3
      public/app/admin/setting.php
  8. 8 10
      public/app/config.table.php
  9. 1 1
      public/app/doc/card.php
  10. 1 1
      public/app/doc/coop.php
  11. 2 2
      public/app/doc/coopfilelist.php
  12. 2 2
      public/app/doc/docinfo.php
  13. 15 13
      public/app/doc/fork.php
  14. 2 2
      public/app/doc/function.php
  15. 7 26
      public/app/doc/pcs2db.php
  16. 11 7
      public/app/group/function.php
  17. 3 32
      public/app/group/get.php
  18. 1 1
      public/app/group/get_name.php
  19. 5 21
      public/app/group/group_del.php
  20. 4 4
      public/app/group/list.php
  21. 1 1
      public/app/group/list_member.php
  22. 19 41
      public/app/group/member_del.php
  23. 39 36
      public/app/group/member_put.php
  24. 39 31
      public/app/group/my_group_put.php
  25. 3 3
      public/app/pcdl/get_res_index.php
  26. 2 2
      public/app/share/function.php
  27. 2 2
      public/app/share/share.js
  28. 10 10
      public/app/studio/file_index.php
  29. 2 2
      public/app/studio/get_res_json.php
  30. 3 3
      public/app/studio/getfilelist.php
  31. 9 9
      public/app/studio/js/index_mydoc.js
  32. 97 68
      public/app/studio/project.php
  33. 2 2
      public/app/studio/project_load.php
  34. 2 2
      public/app/studio/project_load_db.php
  35. 43 0
      public/db/sqlite/fileindex/up.sql
  36. 35 0
      public/db/sqlite/group/up.sql
  37. 9 1
      public/documents/testing.md
  38. 9 0
      v1/scripts/install4.sh
  39. 181 0
      v1/scripts/migrations/20220205084100_group_info_copy.php
  40. 170 0
      v1/scripts/migrations/20220205092400_group_member_copy.php
  41. 188 0
      v1/scripts/migrations/20220206143600_fileindex_copy.php

+ 11 - 0
app/Models/FileIndex.php

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

+ 11 - 0
app/Models/GroupInfo.php

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

+ 11 - 0
app/Models/GroupMember.php

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

+ 41 - 0
database/migrations/2022_02_05_020339_create_group_infos_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateGroupInfosTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('group_infos', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('uid',36)->uniqid()->index();
+            $table->string('name',64)->uniqid()->index();
+            $table->string('description',1024)->nullable();
+            $table->integer('status')->default(30);
+            $table->string('owner',36)->index();
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+            $table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('group_infos');
+    }
+}

+ 43 - 0
database/migrations/2022_02_05_024244_create_group_members_table.php

@@ -0,0 +1,43 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateGroupMembersTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('group_members', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('user_id',36)->index();
+            $table->string('group_id',36)->index();
+            $table->string('group_name',64)->nullable();
+
+            $table->integer('power')->default(1);
+            $table->integer('level')->default(0);
+            $table->integer('status')->default(1)->index();
+            $table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+
+            $table->unique(['user_id','group_id']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('group_members');
+    }
+}

+ 57 - 0
database/migrations/2022_02_06_075148_create_file_indices_table.php

@@ -0,0 +1,57 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateFileIndicesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('file_indices', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('uid',36)->uniqid();
+            $table->string('parent_id',36)->nullable()->index();
+            $table->bigInteger('user_id')->index();
+            $table->integer('book');
+            $table->integer('paragraph');
+            $table->string('channal',36)->nullable()->index();
+            $table->string('file_name',128)->nullable()->index();
+            $table->string('title',128)->index();
+            $table->string('tag',512)->nullable()->index();
+            $table->integer('status')->default(1);
+            $table->integer('file_size')->nullable();
+            $table->integer('share')->default(0);
+            $table->text('doc_info');
+            $table->text('doc_block');
+
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+            $table->bigInteger('accese_time');
+
+            $table->timestamp('created_at')->useCurrent()->index();
+            $table->timestamp('accesed_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+            $table->timestamp('deleted_at')->nullable();
+
+            $table->index(['book','paragraph']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('file_indices');
+    }
+}

+ 3 - 3
public/app/admin/setting.php

@@ -124,11 +124,11 @@ foreach ($Fetch as $album) {
         echo "</table>";
         break;
     case "share":
-        PDO_Connect("" . _FILE_DB_FILEINDEX_);
-        $query = "SELECT count(*) from 'fileindex' where share=1";
+        PDO_Connect(_FILE_DB_FILEINDEX_);
+        $query = "SELECT count(*) from "._TABLE_FILEINDEX_." where share=1";
         $file_count = PDO_FetchOne($query);
         echo "共计:{$file_count} 个共享文件";
-        $query = "SELECT * from 'fileindex' where share=1 limit 0,100";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where share=1 limit 100";
         $file_share = PDO_FetchAll($query);
         echo "<table>";
         echo "<tr><th>id</th><th>user id</th><th>Title</th><th>Size</th><th></th></tr>";

+ 8 - 10
public/app/config.table.php

@@ -307,8 +307,8 @@ define("_SQLITE_TABLE_GROUP_INFO_", "group_info");
 define("_SQLITE_TABLE_GROUP_MEMBER_", "group_member");
 
 define("_PG_DB_GROUP_", _PDO_DB_DSN_);
-define("_PG_TABLE_GROUP_INFO_", "group_info");
-define("_PG_TABLE_GROUP_MEMBER_", "group_member");
+define("_PG_TABLE_GROUP_INFO_", "group_infos");
+define("_PG_TABLE_GROUP_MEMBER_", "group_members");
 
 # 逐词解析文件索引
 define("_SQLITE_DB_FILEINDEX_", "sqlite:" . __DIR__ . "/../tmp/user/fileindex.db");
@@ -316,8 +316,7 @@ define("_SQLITE_TABLE_FILEINDEX_", "fileindex");
 define("_SQLITE_TABLE_FILEINDEX_POWER_", "power");
 
 define("_PG_DB_FILEINDEX_", _PDO_DB_DSN_);
-define("_PG_TABLE_FILEINDEX_", "fileindex");
-define("_PG_TABLE_FILEINDEX_POWER_", "power");
+define("_PG_TABLE_FILEINDEX_", "file_indices");
 
 # 课程
 define("_SQLITE_DB_COURSE_", "sqlite:" . __DIR__ . "/../tmp/user/course.db3");
@@ -651,14 +650,13 @@ define("_FILE_DB_USER_SHARE_", _PG_DB_USER_SHARE_);
 define("_TABLE_USER_SHARE_", _PG_TABLE_USER_SHARE_);
 
 # 工作组
-define("_FILE_DB_GROUP_", _SQLITE_DB_GROUP_);
-define("_TABLE_GROUP_INFO_", _SQLITE_TABLE_GROUP_INFO_);
-define("_TABLE_GROUP_MEMBER_", _SQLITE_TABLE_GROUP_MEMBER_);
+define("_FILE_DB_GROUP_", _PG_DB_GROUP_);
+define("_TABLE_GROUP_INFO_", _PG_TABLE_GROUP_INFO_);
+define("_TABLE_GROUP_MEMBER_", _PG_TABLE_GROUP_MEMBER_);
 
 # 逐词解析文件索引
-define("_FILE_DB_FILEINDEX_", _SQLITE_DB_FILEINDEX_);
-define("_TABLE_FILEINDEX_", _SQLITE_TABLE_FILEINDEX_);
-define("_TABLE_FILEINDEX_POWER_", _SQLITE_TABLE_FILEINDEX_POWER_);
+define("_FILE_DB_FILEINDEX_", _PG_DB_FILEINDEX_);
+define("_TABLE_FILEINDEX_", _PG_TABLE_FILEINDEX_);
 
 
 # 用户自定义书

+ 1 - 1
public/app/doc/card.php

@@ -9,7 +9,7 @@ require_once '../ucenter/function.php';
 if (isset($_GET["id"])) {
 	$output["id"]=$_GET["id"];
 	PDO_Connect( _FILE_DB_FILEINDEX_);
-	$query = "SELECT title,create_time,user_id as owner FROM fileindex  WHERE id = ? ";
+	$query = "SELECT title,create_time,user_id as owner FROM "._TABLE_FILEINDEX_."  WHERE uid = ? ";
 	$result = PDO_FetchRow($query, array($_GET["id"]));
 	$strData="";
 	if ($result) {

+ 1 - 1
public/app/doc/coop.php

@@ -52,7 +52,7 @@ $powerlist["30"] = "可修改";
 PDO_Connect(_FILE_DB_FILEINDEX_);
 
 echo "<input id='doc_coop_docid' type='hidden' value='{$_doc_id}' />";
-$query = "SELECT * from fileindex where id = ? ";
+$query = "SELECT * from "._TABLE_FILEINDEX_." where uid = ? ";
 $Fetch = PDO_FetchAll($query, array($_doc_id));
 $iFetch = count($Fetch);
 if ($iFetch > 0) {

+ 2 - 2
public/app/doc/coopfilelist.php

@@ -20,7 +20,7 @@ else{
     $Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
     $result=array();
     foreach($Fetch as $row){
-        $query = "SELECT * from fileindex where id = ?  ";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where uid = ?  ";
         $FetchFile = PDO_FetchAll($query,array($row['doc_id']));
         if(count($FetchFile)>0){
             $FetchFile[0]["power"]=$row["power"];
@@ -28,7 +28,7 @@ else{
             $FetchFile[0]["power_create_time"]=$row["create_time"];
             $FetchFile[0]["power_modify_time"]=$row["modify_time"];
             $FetchFile[0]["user_name"]=ucenter_get($FetchFile[0]["user_id"],"");
-            $query = "SELECT id from fileindex where parent_id = ? and user_id = ? ";
+            $query = "SELECT uid from "._TABLE_FILEINDEX_." where parent_id = ? and user_id = ? ";
             $FetchFile[0]["my_doc_id"] = PDO_FetchOne($query,array($row['doc_id'],$uid));
             $FetchFile[0]["path"] = _get_para_path($FetchFile[0]["book"],$FetchFile[0]["paragraph"]);
             $result[] = $FetchFile[0];

+ 2 - 2
public/app/doc/docinfo.php

@@ -15,11 +15,11 @@ if ($_COOKIE["userid"]) {
     $isLogin = true;
 }
 
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
+PDO_Connect(_FILE_DB_FILEINDEX_);
 if (isset($_GET["id"])) {
 
     $doc_id = $_GET["id"];
-    $query = "SELECT * from fileindex where id = ? ";
+    $query = "SELECT * from "._TABLE_FILEINDEX_." where uid = ? ";
     $Fetch = PDO_FetchAll($query, array($doc_id));
     $iFetch = count($Fetch);
     if ($iFetch > 0) {

+ 15 - 13
public/app/doc/fork.php

@@ -29,9 +29,9 @@ if (isset($_GET["doc_id"]) == false) {
     echo "没有 文档编号";
     exit;
 }
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
+PDO_Connect( _FILE_DB_FILEINDEX_);
 $doc_id = $_GET["doc_id"];
-$query = "select * from fileindex where id= ? ";
+$query = "SELECT * from "._TABLE_FILEINDEX_." where uid= ? ";
 $Fetch = PDO_FetchAll($query, array($doc_id));
 $iFetch = count($Fetch);
 if ($iFetch > 0) {
@@ -104,7 +104,7 @@ if (isset($_GET["channel"]) == false) {
 {
     PDO_Connect( _FILE_DB_FILEINDEX_,_DB_USERNAME_,_DB_PASSWORD_);
     $doc_id = $_GET["doc_id"];
-    $query = "SELECT * from fileindex where id= ? ";
+    $query = "SELECT * from "._TABLE_FILEINDEX_." where uid= ? ";
     $Fetch = PDO_FetchAll($query, array($doc_id));
     $iFetch = count($Fetch);
     if ($iFetch > 0) {
@@ -123,7 +123,7 @@ if (isset($_GET["channel"]) == false) {
         } else {
             //别人的文档
             //查询自己是否以前打开过
-            $query = "SELECT * from fileindex where parent_id='{$doc_id}' and user_id='{$uid}' ";
+            $query = "SELECT * from "._TABLE_FILEINDEX_." where parent_id='{$doc_id}' and user_id='{$uid}' ";
             $FetchSelf = PDO_FetchAll($query);
             $iFetchSelf = count($FetchSelf);
             if ($iFetchSelf > 0) {
@@ -139,8 +139,8 @@ if (isset($_GET["channel"]) == false) {
                 echo "<div style='display:none;'>";
                 //获取文件路径
 
-                PDO_Connect("" . _FILE_DB_USERINFO_);
-                $query = "select userid from user where id='{$owner}'";
+                PDO_Connect( _FILE_DB_USERINFO_);
+                $query = "SELECT userid from user where id='{$owner}'";
                 $FetchUid = PDO_FetchOne($query);
                 if ($FetchUid) {
                     //$source=$dir_user_base.$FetchUid.$dir_mydocument.$filename;
@@ -309,8 +309,10 @@ if (isset($_GET["channel"]) == false) {
                     //插入记录到文件索引
                     $filesize = 0;
                     //服务器端文件列表
-                    PDO_Connect("" . _FILE_DB_FILEINDEX_);
-                    $query = "INSERT INTO fileindex ('id',
+                    PDO_Connect(_FILE_DB_FILEINDEX_);
+                    $query = "INSERT INTO "._TABLE_FILEINDEX_." (
+                                                        'id',
+                                                        'uid',
                                                        'parent_id',
                                                        'user_id',
                                                        'book',
@@ -325,8 +327,7 @@ if (isset($_GET["channel"]) == false) {
                                                        'file_size',
                                                        'share',
                                                        'doc_info',
-                                                       'doc_block',
-                                                       'receive_time'
+                                                       'doc_block'
                                                        )
                                         VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                     $stmt = $PDO->prepare($query);
@@ -336,7 +337,9 @@ if (isset($_GET["channel"]) == false) {
                     $newDocInfo["parent_id"] = $orgFileInfo["id"];
                     $newDocInfo["user_id"] = $_COOKIE["uid"];
                     $newDocInfo["doc_block"] = json_encode($newDocBlockList, JSON_UNESCAPED_UNICODE);
-                    $newData = array($newDocInfo["id"],
+                    $newData = array(
+                        $snowflake->id(),
+                        $newDocInfo["id"],
                         $newDocInfo["parent_id"],
                         $newDocInfo["user_id"],
                         $newDocInfo["book"],
@@ -351,8 +354,7 @@ if (isset($_GET["channel"]) == false) {
                         $newDocInfo["file_size"],
                         $newDocInfo["share"],
                         $newDocInfo["doc_info"],
-                        $newDocInfo["doc_block"],
-                        mTime(),
+                        $newDocInfo["doc_block"]
                     );
                     $stmt->execute($newData);
                     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {

+ 2 - 2
public/app/doc/function.php

@@ -6,8 +6,8 @@ require_once "../public/_pdo.php";
 function pcs_get_title($id)
 {
     if (isset($id)) {
-		PDO_Connect("" . _FILE_DB_FILEINDEX_);
-		$query = "SELECT title FROM fileindex  WHERE id = ? ";
+		PDO_Connect(_FILE_DB_FILEINDEX_);
+		$query = "SELECT title FROM "._TABLE_FILEINDEX_."  WHERE uid = ? ";
 		$file = PDO_FetchRow($query, array($id));
 		if ($file) {
 			return $file["title"];

+ 7 - 26
public/app/doc/pcs2db.php

@@ -24,9 +24,9 @@ if (isset($_GET["doc_id"]) == false) {
     echo "没有 文档编号";
     exit;
 }
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
+PDO_Connect(_FILE_DB_FILEINDEX_);
 $doc_id = $_GET["doc_id"];
-$query = "SELECT * from fileindex where id= ? ";
+$query = "SELECT book,paragraph from "._TABLE_FILEINDEX_." where uid= ? ";
 $Fetch = PDO_FetchAll($query, array($doc_id));
 $iFetch = count($Fetch);
 if ($iFetch > 0) {
@@ -96,8 +96,8 @@ if (isset($_GET["channel"]) == false) {
 }
 
 $dir = _DIR_USER_DOC_ . '/' . $_COOKIE["userid"] . _DIR_MYDOCUMENT_;
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
-$query = "SELECT file_name, doc_info, modify_time from fileindex where id=? ";
+PDO_Connect(_FILE_DB_FILEINDEX_);
+$query = "SELECT file_name, doc_info, modify_time from "._TABLE_FILEINDEX_." where uid=? ";
 $Fetch = PDO_FetchRow($query, array($_GET["doc_id"]));
 
 if ($Fetch === false) {
@@ -434,28 +434,9 @@ $dataBlock = $xml->xpath('//block');
     //插入记录到文件索引
     $filesize = 0;
     //服务器端文件列表
-    PDO_Connect("" . _FILE_DB_FILEINDEX_);
-    $query = "INSERT INTO fileindex ('id',
-                                   'parent_id',
-                                   'user_id',
-                                   'book',
-                                   'paragraph',
-                                   'file_name',
-                                   'title',
-                                   'tag',
-                                   'status',
-                                   'create_time',
-                                   'modify_time',
-                                   'accese_time',
-                                   'file_size',
-                                   'share',
-                                   'doc_info',
-                                   'doc_block',
-                                   'receive_time'
-                                   )
-                    VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-    $stmt = $PDO->prepare($query);
-    $query = "UPDATE 'fileindex' SET 'doc_info' = ? , 'doc_block' = ?  WHERE id = ? ";
+    PDO_Connect( _FILE_DB_FILEINDEX_);
+
+    $query = "UPDATE "._TABLE_FILEINDEX_." SET 'doc_info' = ? , 'doc_block' = ?  WHERE id = ? ";
     $stmt = $PDO->prepare($query);
     $newData = array(
         $strHead,

+ 11 - 7
public/app/group/function.php

@@ -8,8 +8,8 @@ require_once '../ucenter/function.php';
 function group_get_name($id)
 {
     if (isset($id)) {
-        PDO_Connect("" . _FILE_DB_GROUP_);
-        $query = "SELECT name FROM group_info  WHERE id=?";
+        PDO_Connect(_FILE_DB_GROUP_);
+        $query = "SELECT name FROM "._TABLE_GROUP_INFO_."  WHERE uid=?";
         $Fetch = PDO_FetchRow($query, array($id));
         if ($Fetch) {
             return $Fetch["name"];
@@ -27,9 +27,9 @@ class GroupInfo
     private $buffer;
     public function __construct()
     {
-        $dns = "" . _FILE_DB_GROUP_;
-        $this->dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
-        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+        $dns = _FILE_DB_GROUP_;
+        $this->dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
+        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $buffer = array();
         $parentId = array();
     }
@@ -43,7 +43,7 @@ class GroupInfo
             return $buffer[$id];
         }
         if ($this->dbh) {
-            $query = "SELECT name FROM group_info WHERE id= ? ";
+            $query = "SELECT name FROM "._TABLE_GROUP_INFO_." WHERE uid= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($id));
             $user = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -62,6 +62,10 @@ class GroupInfo
 	
 	public function getParentId($id)
     {
+        /*
+        */
+        return 0;
+
         if (empty($id)) {
             return "";
         }
@@ -69,7 +73,7 @@ class GroupInfo
             return $parentId[$id];
         }
         if ($this->dbh) {
-            $query = "SELECT parent FROM group_info WHERE id= ? ";
+            $query = "SELECT parent FROM "._TABLE_GROUP_INFO_." WHERE uid= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($id));
             $user = $stmt->fetch(PDO::FETCH_ASSOC);

+ 3 - 32
public/app/group/get.php

@@ -11,42 +11,13 @@ $output = array();
 if (isset($_GET["id"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     $id = $_GET["id"];
-    $query = "SELECT * FROM group_info  WHERE id = ? ";
+    $query = "SELECT * FROM "._TABLE_GROUP_INFO_."  WHERE uid = ? ";
     $Fetch = PDO_FetchRow($query, array($id));
     if ($Fetch) {
         $output["info"] = $Fetch;
-        if ($Fetch["parent"] == 0) {
-            #顶级组 列出小组
-            $query = "SELECT * FROM group_info  WHERE parent = ? ";
-            $FetchList = PDO_FetchAll($query, array($id));
-            $output["children"] = $FetchList;
-        } else {
-            $output["children"] = array();
-            $query = "SELECT * FROM group_info  WHERE id = ? ";
-            $parent_group = PDO_FetchRow($query, array($Fetch["parent"]));
-            $output["parent"] = $parent_group;
-        }
         #列出组共享资源
-        {
-			/*
-            PDO_Connect("" . _FILE_DB_FILEINDEX_);
-            $query = "SELECT * FROM power  WHERE user = ? ";
-            $fileList = PDO_FetchAll($query, array($id));
-            foreach ($fileList as $key => $value) {
-                # code...
-                $query = "SELECT title FROM fileindex  WHERE id = ? ";
-                $file = PDO_FetchRow($query, array($value["doc_id"]));
-                if ($file) {
-                    $fileList[$key]["title"] = $file["title"];
-                } else {
-                    $fileList[$key]["title"] = "";
-                }
-			}
-			
-			$output["file"] = $fileList;
-			*/
-			$output["file"] =share_res_list_get($id);
-        }
+		$output["file"] =share_res_list_get($id);
+
     }
 }
 echo json_encode($output, JSON_UNESCAPED_UNICODE);

+ 1 - 1
public/app/group/get_name.php

@@ -9,7 +9,7 @@ require_once '../ucenter/function.php';
 $output = array();
 if (isset($_GET["name"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
-    $query = "SELECT * FROM group_info  WHERE name like ? and parent=0 limit 0,5";
+    $query = "SELECT * FROM "._TABLE_GROUP_INFO_."  WHERE name like ?  limit 50";
     $Fetch = PDO_FetchAll($query, array("%" . $_GET["name"] . "%"));
 
     $user_info = new UserInfo();

+ 5 - 21
public/app/group/group_del.php

@@ -7,35 +7,19 @@ $respond = array("status" => 0, "message" => "");
 if (isset($_COOKIE["userid"]) && isset($_POST["groupid"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     #TODO 先查是否有删除权限
-    $query = "SELECT parent from group_info where id=? and owner=? ";
+    $query = "SELECT id from "._TABLE_GROUP_INFO_." where uid=? and owner=? ";
     $gInfo = PDO_FetchRow($query, array($_POST["groupid"], $_COOKIE["userid"]));
     if ($gInfo) {
         #删除group info
-        $query = "DELETE from group_info where id=? and owner=? ";
+        $query = "DELETE from "._TABLE_GROUP_INFO_." where uid=? and owner=? ";
         PDO_Execute($query, array($_POST["groupid"], $_COOKIE["userid"]));
         #删除 组员
-        $query = "DELETE from group_member where group_id=? ";
+        $query = "DELETE from "._TABLE_GROUP_MEMBER_." where group_id=? ";
         PDO_Execute($query, array($_POST["groupid"]));
         #删除到此组的分享
+        $query = "DELETE from "._TABLE_USER_SHARE_." where cooperator_id=? and cooperator_type=1 ";
+        PDO_Execute($query, array($_POST["groupid"]));
 
-        #查询是否有子项目
-        $query = "SELECT id from group_info where parent=? ";
-        $project = PDO_FetchAll($query, array($_POST["groupid"]));
-        if (count($project)) {
-            $arrProject = array();
-            foreach ($project as $key => $value) {
-                # code...
-                $arrProject[] = $value["id"];
-            }
-            $place_holders = implode(',', array_fill(0, count($arrProject), '?'));
-            #删除 parent info
-            $query = "DELETE from group_info where id IN ($place_holders) ";
-            PDO_Execute($query, $arrProject);
-            #删除 parent 组员
-            $query = "DELETE from group_member where group_id IN ($place_holders) ";
-            PDO_Execute($query, $arrProject);
-            #删除到此组的分享
-        }
     } else {
         $respond['status'] = 1;
         $respond['message'] = "no power to delete ";

+ 4 - 4
public/app/group/list.php

@@ -7,12 +7,12 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
 //列出 我j参与的群组
-PDO_Connect("" . _FILE_DB_GROUP_);
-$query = "SELECT group_name,group_id,power FROM group_member  WHERE level = 0 and user_id=?";
-$Fetch = PDO_FetchAll($query, array($_COOKIE["userid"]));
+PDO_Connect(_FILE_DB_GROUP_);
+$query = "SELECT group_name,group_id,power FROM "._TABLE_GROUP_MEMBER_."  WHERE level = 0 and user_id=?";
+$Fetch = PDO_FetchAll($query, array($_COOKIE["user_uid"]));
 foreach ($Fetch as $key => $value) {
 	# code...
-	$query = "SELECT name FROM group_info  WHERE id=?";
+	$query = "SELECT name FROM "._TABLE_GROUP_INFO_."  WHERE uid=?";
 	$groupInfo = PDO_FetchRow($query, array($value["group_id"]));
 	if($groupInfo){
 		$Fetch[$key]["group_name"]=$groupInfo["name"];

+ 1 - 1
public/app/group/list_member.php

@@ -10,7 +10,7 @@ $output = array();
 if (isset($_GET["id"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     $id = $_GET["id"];
-    $query = "SELECT user_id FROM group_member  WHERE group_id = ? ";
+    $query = "SELECT user_id FROM "._TABLE_GROUP_MEMBER_."  WHERE group_id = ? ";
     $output = PDO_FetchAll($query, array($id));
     $userinfo = new UserInfo();
     foreach ($output as $key => $value) {

+ 19 - 41
public/app/group/member_del.php

@@ -4,6 +4,13 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
 $respond = array("status" => 0, "message" => "");
+set_exception_handler(function($e){
+    $respond['status'] = 1;
+    $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
+    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+	exit;
+});
+
 if (!isset($_COOKIE["userid"])) {
     $respond['status'] = 1;
     $respond['message'] = "尚未登录";
@@ -14,28 +21,22 @@ if (isset($_POST["groupid"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     $mypower = 100;
     # 先查是否有删人权限
-    $query = "SELECT * from group_info where id=?";
+    #是否是拥有者
+    $query = "SELECT * from "._TABLE_GROUP_INFO_." where uid=?";
     $fc = PDO_FetchRow($query, array($_POST["groupid"]));
     if ($fc) {
-        if ($fc["parent"] == 0) {
-            if ($fc["owner"] == $_COOKIE["userid"]) {
-                $mypower = 0;
-            }
-        } else {
-            $query = "SELECT owner  from group_info where id=?";
-            $g_parent = PDO_FetchRow($query, array($fc["parent"]));
-            if ($g_parent && $g_parent["owner"] == $_COOKIE["userid"]) {
-                $mypower = 0;
-            }
+        if ($fc["owner"] == $_COOKIE["userid"]) {
+            $mypower = 0;
         }
     }
     if ($mypower != 0) {
         #非拥有者,看看是不是管理员
-        $query = "SELECT power from group_member where user_id=? and group_id=? ";
-        $power = PDO_FetchRow($query, array($_COOKIE["userid"], $_POST["groupid"]));
+        $query = "SELECT power from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=? ";
+        $power = PDO_FetchRow($query, array($_COOKIE["user_uid"], $_POST["groupid"]));
         if ($power) {
             $mypower = (int) $power["power"];
         }
+        #普通成员无权移除他人
         if ($mypower > 1) {
             $respond['status'] = 1;
             $respond['message'] = "no power to remove memeber";
@@ -45,7 +46,7 @@ if (isset($_POST["groupid"])) {
     }
 
     # 查询被删除人的权限
-    $query = "SELECT power from group_member where user_id=? and group_id=? ";
+    $query = "SELECT power from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=? ";
     $power = PDO_FetchRow($query, array($_POST["userid"], $_POST["groupid"]));
     $userpower = 0;
     if ($power) {
@@ -54,39 +55,16 @@ if (isset($_POST["groupid"])) {
     #操作人的权限不足
     if ($mypower >= $userpower) {
         $respond['status'] = 1;
-        $respond['message'] = "can not removed";
+        $respond['message'] = "can not removed 权限不足";
         echo json_encode($respond, JSON_UNESCAPED_UNICODE);
         exit;
     }
 
-    $query = "SELECT * from group_info where id=?";
-    $fc = PDO_FetchRow($query, array($_POST["groupid"]));
-    if ($fc) {
-        $idList = array();
-        $idList[] = $_POST["userid"];
-        $idList[] = $_POST["groupid"];
-        if ($fc["parent"] == 0) {
-            //group
-            $level = 0;
-            #查询project
-            $query = "SELECT id from group_info where parent=?";
-            $g_project = PDO_FetchAll($query, array($_POST["groupid"]));
-            foreach ($g_project as $key => $parentid) {
-                # code...
-                $idList[] = $parentid["id"];
-            }
-        }
-    }
     #删除
-    $place_holders = implode(',', array_fill(0, count($idList), '?'));
-    $query = "DELETE from group_member where user_id=? and group_id IN ($place_holders)";
-    PDO_Execute($query, $idList);
 
-    if (!$sth || ($sth && $sth->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        $respond['status'] = 1;
-        $respond['message'] = $error[2];
-    }
+    $query = "DELETE from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id =? ";
+    PDO_Execute($query, array($_POST["userid"], $_POST["groupid"]));
+
 } else {
     $respond['status'] = 1;
     $respond['message'] = "参数不足";

+ 39 - 36
public/app/group/member_put.php

@@ -2,56 +2,59 @@
 require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
+
 
 $respond = array("status" => 0, "message" => "");
+
+set_exception_handler(function($e){
+    $respond['status'] = 1;
+    $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
+    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+	exit;
+});
 if (isset($_COOKIE["userid"]) && isset($_POST["groupid"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
-    #TODO 先查是否有加人权限
-    $query = "SELECT power from group_member where user_id=? and group_id=? ";
+    #先查是否有加人权限 0:拥有者,1.管理员
+    $query = "SELECT power from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=? ";
     $power = PDO_FetchRow($query, array($_COOKIE["userid"], $_POST["groupid"]));
-    if ($power) {
-        if ($power["power"] > 1) {
-            $respond['status'] = 1;
-            $respond['message'] = "no power to add memeber";
-            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-            exit;
-        }
+    if (!$power || $power["power"] > 1) {
+        $respond['status'] = 1;
+        $respond['message'] = "no power to add memeber";
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
     }
 
-    $query = "SELECT * from group_info where id=?";
-    $fc = PDO_FetchRow($query, array($_POST["groupid"]));
-    if ($fc) {
-        if ($fc["parent"] == 0) {
-            $level = 0;
-        } else {
-            $level = 1;
-            #子小组要插入两条记录 第一条插入父层级
-            $query = "SELECT * from group_info where id=?";
-            $g_parent = PDO_FetchRow($query, array($fc["id"]));
-            $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )  VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
-            $sth = $PDO->prepare($query);
-            $sth->execute(array($_POST["userid"], $fc["parent"], 2, $$g_parent["name"], 0, 1));
-            $respond = array("status" => 0, "message" => "");
-            if (!$sth || ($sth && $sth->errorCode() != 0)) {
-                $error = PDO_ErrorInfo();
-                $respond['status'] = 1;
-                $respond['message'] = $error[2];
-            }
-        }
-    }
-    #查询这个
-    $query = "SELECT * from group_info where id=?";
+    #查询组信息
+    $query = "SELECT * from "._TABLE_GROUP_INFO_." where uid=?";
     $g_curr = PDO_FetchRow($query, array($_POST["groupid"]));
+    if (!$g_curr) {
+        $respond['status'] = 1;
+        $respond['message'] = '组不存在';
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
+    }
+#查询是否有重复记录
+    $query = "SELECT * from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=?";
+    $isExist = PDO_FetchRow($query, array($_POST["userid"], $_POST["groupid"]));
+    if ($isExist) {
+        $respond['status'] = 1;
+        $respond['message'] = '组员已经存在';
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
+    }
 
-    $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )
-		VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
+    $query = "INSERT INTO "._TABLE_GROUP_MEMBER_." (id,  user_id  , group_id  , power , group_name , level ,  status )
+		VALUES  (  ? , ? , ? , ? , ?  ,? ,?) ";
     $sth = $PDO->prepare($query);
-    $sth->execute(array($_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], $level, 1));
-    $respond = array("status" => 0, "message" => "");
+    $sth->execute(array($snowflake->id(),$_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], 0, 1));
     if (!$sth || ($sth && $sth->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
         $respond['status'] = 1;
         $respond['message'] = $error[2];
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
     }
 }
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 39 - 31
public/app/group/my_group_put.php

@@ -3,41 +3,49 @@
 require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
+
+$respond = array("status" => 0, "message" => "ok");
+set_exception_handler(function($e){
+    $respond['status'] = 1;
+    $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
+	exit;
+});
+
 
-$respond = array("status" => 0, "message" => "");
 if (isset($_COOKIE["userid"])) {
     PDO_Connect(_FILE_DB_GROUP_);
-	#先查询是否有重复的组名
-	$query = "SELECT id FROM group_info  WHERE name = ? ";
-    $Fetch = PDO_FetchRow($query, array($_POST["name"]));
-	if ($Fetch) {
-		$respond['status'] = 1;
-        $respond['message'] = "错误:有相同的组名称,请选择另一个名称。";
-		echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-		exit;
-	}
-    $query = "INSERT INTO group_info ( id,  parent  , name  , description ,  status , owner ,create_time )
-	                       VALUES  ( ?, ? , ? , ? , ? , ?  ,? ) ";
-    $sth = $PDO->prepare($query);
-    $newid = UUID::v4();
-    $sth->execute(array($newid, $_POST["parent"], $_POST["name"], "", 1, $_COOKIE["userid"], mTime()));
-    $respond = array("status" => 0, "message" => "");
-    if (!$sth || ($sth && $sth->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        $respond['status'] = 1;
-        $respond['message'] = $error[2];
-    }
+    try{
+        $PDO->beginTransaction();
+        #先查询是否有重复的组名
+        $query = "SELECT id FROM "._TABLE_GROUP_INFO_."  WHERE name = ? ";
+        $Fetch = PDO_FetchRow($query, array($_POST["name"]));
+        if ($Fetch) {
+            $respond['status'] = 1;
+            $respond['message'] = "错误:有相同的组名称,请选择另一个名称。";
+            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+        $query = "INSERT INTO "._TABLE_GROUP_INFO_." ( id, uid  , name  , description  , owner ,create_time,modify_time )
+                            VALUES  ( ?, ? , ? , ? , ? , ?  ,? ) ";
+        $sth = $PDO->prepare($query);
+        $newid = UUID::v4();
+        $sth->execute(array($snowflake->id(),$newid,  $_POST["name"], "",  $_COOKIE["user_uid"], mTime(), mTime()));
 
-	#将创建者添加到成员中
-    $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )
-		VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
-    $sth = $PDO->prepare($query);
-    $sth->execute(array($_COOKIE["userid"], $newid, 0, $_POST["name"], 0, 1));
-    $respond = array("status" => 0, "message" => "");
-    if (!$sth || ($sth && $sth->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        $respond['status'] = 1;
-        $respond['message'] = $error[2];
+
+        #将创建者添加到成员中
+        $query = "INSERT INTO "._TABLE_GROUP_MEMBER_." (id,  user_id  , group_id  , power , group_name , level ,  status )
+            VALUES  ( ? , ? , ? , ? , ? , ?  ,? ) ";
+        $sth = $PDO->prepare($query);
+        $sth->execute(array($snowflake->id(),$_COOKIE["user_uid"], $newid, 0, $_POST["name"], 0, 1));
+        $PDO->commit();    
+    }catch (Exception $e) {
+        $PDO->rollBack();
+    	$respond['status']=1;
+        $respond['message']="Failed: " . $e->getMessage();
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
     }
+
 }
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 3 - 3
public/app/pcdl/get_res_index.php

@@ -171,9 +171,9 @@ if ($album == -1) {
 
         }
         //查共享文档
-        PDO_Connect("" . _FILE_DB_FILEINDEX_);
-        $query = "select * from fileindex where book='$book' and paragraph=$paragraph  and status>0 and share>0 order by create_time";
-        $Fetch = PDO_FetchAll($query);
+        PDO_Connect(_FILE_DB_FILEINDEX_);
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where book=? and paragraph=?  and status>0 and share>0 order by create_time";
+        $Fetch = PDO_FetchAll($query,array($book,$paragraph));
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
             echo "<ul class='search_list'>";

+ 2 - 2
public/app/share/function.php

@@ -17,7 +17,7 @@ function share_res_list_get($userid,$res_type=-1){
 	# 找我加入的群
 	$dbhGroup = new PDO(_FILE_DB_GROUP_, _DB_USERNAME_, _DB_PASSWORD_);
     $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-	$query = "SELECT group_id from group_member where user_id = ?  limit 200";
+	$query = "SELECT group_id from "._TABLE_GROUP_MEMBER_." where user_id = ?  limit 500";
 	$stmtGroup = $dbhGroup->prepare($query);
 	$stmtGroup->execute(array($userid));
 	$my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
@@ -146,7 +146,7 @@ function share_get_res_power($userid,$res_id){
 		# 找我加入的群
 		$dbhGroup = new PDO(_FILE_DB_GROUP_, _DB_USERNAME_, _DB_PASSWORD_);
 		$dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-		$query = "SELECT group_id from group_member where user_id = ?  limit 100";
+		$query = "SELECT group_id from "._TABLE_GROUP_MEMBER_." where user_id = ?  limit 500";
 		$stmtGroup = $dbhGroup->prepare($query);
 		$stmtGroup->execute(array($userid));
 		$my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);

+ 2 - 2
public/app/share/share.js

@@ -174,7 +174,7 @@ function username_search(keyword, type) {
 					for (const iterator of result) {
 						html +=
 							"<li onclick=\"user_selected('" +
-							iterator.id +
+							iterator.uid +
 							"','" +
 							iterator.username +
 							"',0)\">" +
@@ -209,7 +209,7 @@ function username_search(keyword, type) {
 					for (const iterator of result) {
 						html +=
 							"<li onclick=\"user_selected('" +
-							iterator.id +
+							iterator.uid +
 							"','" +
 							iterator.name +
 							"',1)\">" +

+ 10 - 10
public/app/studio/file_index.php

@@ -35,14 +35,14 @@ switch ($op) {
     case "list":
         break;
     case "get";
-        $query = "select * from fileindex where user_id='$uid' AND  id='{$doc_id}'";
-        $Fetch = PDO_FetchAll($query);
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id=? AND  id=?";
+        $Fetch = PDO_FetchAll($query,[$uid,$doc_id]);
         echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
         break;
     case "getall";
         //
-        $query = "select * from fileindex where user_id='$uid' AND  id='{$_POST["doc_id"]}'";
-        $Fetch = PDO_FetchAll($query);
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id=? AND  id=?";
+        $Fetch = PDO_FetchAll($query,[$uid,$_POST["doc_id"]]);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
             echo json_encode($Fetch[0], JSON_UNESCAPED_UNICODE);
@@ -54,8 +54,8 @@ switch ($op) {
             $value = mTime();
         }
         $doc_id = $_POST["doc_id"];
-        $query = "UPDATE fileindex SET $field='$value' where user_id='$uid' AND  id='{$doc_id}'";
-        $stmt = @PDO_Execute($query);
+        $query = "UPDATE "._TABLE_FILEINDEX_." SET $field='$value' where user_id=? AND  uid=?";
+        $stmt = @PDO_Execute($query,array($uid,$doc_id));
         if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
             $error = PDO_ErrorInfo();
             echo json_encode(array("error" => $error[2], "message" => $query), JSON_UNESCAPED_UNICODE);
@@ -80,7 +80,7 @@ switch ($op) {
                 }
                 $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                 $strFileList .= ")";
-                $query = "UPDATE fileindex SET share='$share' where user_id='$uid' AND   id in $strFileList";
+                $query = "UPDATE "._TABLE_FILEINDEX_." SET share='$share' where user_id='$uid' AND   uid in $strFileList";
                 $stmt = @PDO_Execute($query);
                 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                     $error = PDO_ErrorInfo();
@@ -105,7 +105,7 @@ switch ($op) {
                     $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                     $strFileList .= ")";
 
-                    $query = "UPDATE fileindex SET status='0',share='0' where user_id='$uid' AND  id in $strFileList";
+                    $query = "UPDATE "._TABLE_FILEINDEX_." SET status='0',share='0' where user_id='$uid' AND  uid in $strFileList";
                     $stmt = @PDO_Execute($query);
                     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                         $error = PDO_ErrorInfo();
@@ -129,7 +129,7 @@ switch ($op) {
                 $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                 $strFileList .= ")";
 
-                $query = "UPDATE fileindex SET status='1' where user_id='$uid' AND  id in $strFileList";
+                $query = "UPDATE "._TABLE_FILEINDEX_." SET status='1' where user_id='$uid' AND  uid in $strFileList";
                 $stmt = @PDO_Execute($query);
                 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                     $error = PDO_ErrorInfo();
@@ -157,7 +157,7 @@ switch ($op) {
                 $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                 $strFileList .= ")";
                 //删除记录
-                $query = "DELETE FROM fileindex WHERE user_id='$uid' AND   id in $strFileList";
+                $query = "DELETE FROM "._TABLE_FILEINDEX_." WHERE user_id='$uid' AND   uid in $strFileList";
                 $stmt = @PDO_Execute($query);
                 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                     $error = PDO_ErrorInfo();

+ 2 - 2
public/app/studio/get_res_json.php

@@ -81,7 +81,7 @@ if ($paragraph > 0) {
     }
     //查共享文档
     PDO_Connect(_FILE_DB_FILEINDEX_);
-    $query = "select * from fileindex where book='$book' and paragraph=$paragraph  and status>0 and share>0 order by create_time";
+    $query = "SELECT * from "._TABLE_FILEINDEX_." where book='$book' and paragraph=$paragraph  and status>0 and share>0 order by create_time";
     $Fetch = PDO_FetchAll($query);
     $iFetch = count($Fetch);
     if ($iFetch > 0) {
@@ -95,7 +95,7 @@ if ($paragraph > 0) {
     }
     //查我的文档
     if ($UID != "") {
-        $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {

+ 3 - 3
public/app/studio/getfilelist.php

@@ -53,13 +53,13 @@ switch ($order_by) {
 
 switch ($status) {
     case "all":
-        $query = "select * from fileindex where user_id='$uid' AND title like '%$keyword%' and status>0 order by $order_by $order";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id='$uid' AND title like '%$keyword%' and status>0 order by $order_by $order";
         break;
     case "share":
-        $query = "select * from fileindex where user_id='$uid' AND  title like '%$keyword%' and status>0 and share=1 order by $order_by $order";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id='$uid' AND  title like '%$keyword%' and status>0 and share=1 order by $order_by $order";
         break;
     case "recycle":
-        $query = "select * from fileindex where user_id='$uid' AND  title like '%$keyword%' and status=0 order by $order_by $order";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id='$uid' AND  title like '%$keyword%' and status=0 order by $order_by $order";
         break;
 }
 $Fetch = PDO_FetchAll($query);

+ 9 - 9
public/app/studio/js/index_mydoc.js

@@ -59,7 +59,7 @@ function file_list_refresh() {
 
 					html += '<div class="file_list_col_1">';
 					html += "<input id='file_check_" + x + '\' type="checkbox" />';
-					html += "<input id='file_id_" + x + "' value='" + file_list[x].id + '\' type="hidden" />';
+					html += "<input id='file_id_" + x + "' value='" + file_list[x].uid + '\' type="hidden" />';
 					html += "</div>";
 
 					html += '<div class="file_list_col_2">';
@@ -68,7 +68,7 @@ function file_list_refresh() {
 						parseInt(file_list[x].share) == 1
 					) {
 						//shared
-						html += "<span onclick=\"file_show_coop_win('" + file_list[x].id + "')\">";
+						html += "<span onclick=\"file_show_coop_win('" + file_list[x].uid + "')\">";
 					} else {
 						html += "<span>";
 					}
@@ -89,16 +89,16 @@ function file_list_refresh() {
 					html += "</svg>";
 					html += "</span>";
 
-					html += "<div id='coop_show_" + file_list[x].id + "' style='display:inline;'></div>";
+					html += "<div id='coop_show_" + file_list[x].uid + "' style='display:inline;'></div>";
 
 					let $link;
 					if (file_list[x].doc_info && file_list[x].doc_info.length > 1) {
-						$link = "<a href='./editor.php?op=opendb&fileid=" + file_list[x].id + "' target='_blank'>";
+						$link = "<a href='./editor.php?op=opendb&fileid=" + file_list[x].uid + "' target='_blank'>";
 					} else {
-						$link = "<a href='./editor.php?op=open&fileid=" + file_list[x].id + "' target='_blank'>";
+						$link = "<a href='./editor.php?op=open&fileid=" + file_list[x].uid + "' target='_blank'>";
 					}
 
-					html += $link + "<span id='title_" + file_list[x].id + "'>" + file_list[x].title;
+					html += $link + "<span id='title_" + file_list[x].uid + "'>" + file_list[x].title;
 					html += "</span></a>";
 
 					//html +="<input type='input' style='diaplay:none;' id='input_title_"+file_list[x].id+"' value='"+file_list[x].title+"' />"
@@ -109,7 +109,7 @@ function file_list_refresh() {
 						"</span>";
 					html +=
 						"<button id='edit_title' type='button' class='icon_btn' onclick=\"title_change('" +
-						file_list[x].id +
+						file_list[x].uid +
 						"','" +
 						file_list[x].title +
 						"')\" >";
@@ -174,7 +174,7 @@ function file_list_refresh() {
 					if (!(file_list[x].doc_info && file_list[x].doc_info.length > 1)) {
 						html +=
 							"<a href='../doc/pcs2db.php?doc_id=" +
-							file_list[x].id +
+							file_list[x].uid +
 							"' target='_blank'>转数据库格式</a>";
 					}
 
@@ -185,7 +185,7 @@ function file_list_refresh() {
 					html += '<span class="icon_btn_tip">' + gLocal.gui.copy_share_link + "</span>";
 					html +=
 						"<button id='edit_title' type='button' class='icon_btn' onclick=\"share_link_copy_to_clipboard('" +
-						file_list[x].id +
+						file_list[x].uid +
 						"')\" >";
 					//html +='	<svg class="icon">';
 					//html +='		<use xlink:href="./svg/icon.svg#ic_rename"></use>';

+ 97 - 68
public/app/studio/project.php

@@ -27,6 +27,13 @@ require_once __DIR__."/../public/snowflakeid.php";
 # 雪花id
 $snowflake = new SnowFlakeId();
 
+set_exception_handler(function($e){
+	echo("error-msg:".$e->getMessage().PHP_EOL);
+	echo("error-file:".$e->getFile().PHP_EOL);
+	echo("error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
 $user_setting = get_setting();
 
 $sLang["1"] = "pali";
@@ -53,9 +60,11 @@ if ($_COOKIE["uid"]) {
     echo '<a href="../ucenter/index.php" target="_blank">' . $_local->gui->not_login . '</a>';
     exit;
 }
+if(isset($_POST["channal"])){
+    $channelClass = new Channal(redis_connect());
+    $channelInfo = $channelClass->getChannal($_POST["channal"]); 
+}
 
-$channelClass = new Channal(redis_connect());
-$channelInfo = $channelClass->getChannal($_POST['channal']);
 
 switch ($op) {
     case "create":
@@ -159,9 +168,10 @@ switch ($op) {
                                     }
                                     $block_id = UUID::v4();
                                     $trans_block_id = UUID::v4();
+                                    $snowId = $snowflake->id();
                                     $block_data[] = array
 									(
-										$snowflake->id(),
+										$snowId,
 										$block_id, 
 										"", 
 										$_POST["channal"], 
@@ -302,59 +312,75 @@ switch ($op) {
                             }
 
                             //服务器端文件列表
-                            PDO_Connect(_FILE_DB_FILEINDEX_);
-                            $query = "INSERT INTO fileindex ('id',
-												'parent_id',
-												'channal',
-												'user_id',
-												'book',
-												'paragraph',
-												'file_name',
-												'title',
-												'tag',
-												'status',
-												'create_time',
-												'modify_time',
-												'accese_time',
-												'file_size',
-												'share',
-												'doc_info',
-												'doc_block',
-												'receive_time'
-												)
-									VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-                            $stmt = $PDO->prepare($query);
+                            $PDO_File = new PDO(_FILE_DB_FILEINDEX_,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+                            $PDO_File->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+                            $queryInsert = "INSERT INTO \""._TABLE_FILEINDEX_."\"  
+ (
+                                    id,
+									uid,
+									parent_id,
+									user_id,
+									book,
+									paragraph,
+									channal,
+									file_name,
+									title,
+									tag,
+									status,
+									file_size,
+									share,
+									doc_info,
+									doc_block,
+									create_time,
+									modify_time,
+									accese_time,
+									accesed_at,
+									updated_at,
+									created_at) 
+									VALUES (? , ? , ? , ? , ?, ? ,? , ? , ? , ?, ? ,? , ? , ? , ?, ? ,? , ? , ? , ?, ? )";
+                            $stmtDEST = $PDO_File->prepare($queryInsert);
                             $doc_id = UUID::v4();
-                            $file_name = $book . '_' . $create_para . '_' . time();
-                            $newData = array(
-                                $doc_id,
-                                "",
-                                $_POST["channal"],
-                                $uid,
-                                $book,
-                                $create_para,
-                                $file_name,
-                                $user_title,
-                                $tag,
-                                1,
-                                mTime(),
-                                mTime(),
-                                mTime(),
-                                0,
-                                0,
-                                $doc_head,
-                                json_encode($block_list, JSON_UNESCAPED_UNICODE),
-                                mTime(),
-                            );
-                            $stmt->execute($newData);
-                            if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                                $error = PDO_ErrorInfo();
-                                echo "error - $error[2] <br>";
-                            } else {
+                            $file_name = $book . '_' . $create_para;
+
+                            $created_at = date("Y-m-d H:i:s.",mTime()/1000).(mTime()%1000)." UTC";
+
+                            $commitData = array(
+                                    $snowflake->id(),
+                                    $doc_id,
+                                    null,
+                                    $uid,
+                                    $book,
+                                    $create_para,
+                                    $_POST["channal"],
+                                    $file_name,
+                                    $user_title,
+                                    $tag,
+                                    1,
+                                    0,
+                                    0,
+                                    $doc_head,
+                                    json_encode($block_list, JSON_UNESCAPED_UNICODE),
+                                    mTime(),
+                                    mTime(),
+                                    mTime(),
+                                    $created_at,
+                                    $created_at,
+                                    $created_at
+                                );
+                            try{
+                                $stmtDEST->execute($commitData); 
                                 echo "成功新建一个文件.";
+                                echo "<a href=\"editor.php?op=opendb&doc_id={$doc_id}\">{$_local->gui->open}</a>";
+                            }catch(PDOException $e){
+                                echo($e->getMessage().PHP_EOL);
+                                echo "<pre>";
+                                print_r($commitData);
+                                echo "</pre>";                                
+                                exit;
                             }
+                            
 
-                            echo "<a href=\"editor.php?op=opendb&doc_id={$doc_id}\">{$_local->gui->open}</a>";
                         }
                         break;
                 }
@@ -837,7 +863,9 @@ switch ($op) {
             //服务器端文件列表
             PDO_Connect(_FILE_DB_FILEINDEX_);
 
-            $query = "INSERT INTO fileindex ('id',
+            $query = "INSERT INTO "._TABLE_FILEINDEX_." (
+                                            'id',
+                                            'uid',
 												'parent_id',
 												'user_id',
 												'book',
@@ -852,13 +880,14 @@ switch ($op) {
 												'file_size',
 												'share',
 												'doc_info',
-												'doc_block',
-												'receive_time'
+												'doc_block'
 												)
 									VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
             $stmt = $PDO->prepare($query);
             $doc_id = UUID::v4();
-            $newData = array($doc_id,
+            $newData = array(
+                $snowflake->id(),
+                $doc_id,
                 "",
                 $uid,
                 $book,
@@ -874,7 +903,6 @@ switch ($op) {
                 0,
                 "",
                 "",
-                mTime(),
             );
             $stmt->execute($newData);
             if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
@@ -906,8 +934,8 @@ switch ($op) {
             PDO_Connect(_FILE_DB_FILEINDEX_);
             if (isset($_GET["doc_id"])) {
                 $doc_id = $_GET["doc_id"];
-                $query = "select * from fileindex where id='$doc_id' ";
-                $Fetch = PDO_FetchAll($query);
+                $query = "SELECT * from "._TABLE_FILEINDEX_." where uid=? ";
+                $Fetch = PDO_FetchAll($query,array($doc_id));
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {
                     //文档信息
@@ -930,16 +958,16 @@ switch ($op) {
                     } else {
                         //别人的文档
                         //查询自己是否以前打开过
-                        $query = "select * from fileindex where parent_id='$doc_id' and user_id='$uid' ";
-                        $FetchSelf = PDO_FetchAll($query);
+                        $query = "SELECT * from "._TABLE_FILEINDEX_." where parent_id=? and user_id=? ";
+                        $FetchSelf = PDO_FetchAll($query,array($doc_id,$uid));
                         $iFetchSelf = count($FetchSelf);
                         if ($iFetchSelf > 0) {
                             //以前打开过
                             echo "已经复制的文档 Already Copy";
-                            $my_doc_id = $FetchSelf[0]["id"];
-                            echo "<a href='../studio/editor.php?op=opendb&fileid={$doc_id}'>{$_local->gui->edit_now}</a>";
+                            $my_doc_id = $FetchSelf[0]["uid"];
+                            echo "<a href='../studio/editor.php?op=opendb&fileid={$my_doc_id}'>{$_local->gui->edit_now}</a>";
                             echo "<script>";
-                            echo "window.location.assign(\"editor.php?op=opendb&fileid={$doc_id}\");";
+                            echo "window.location.assign(\"editor.php?op=opendb&fileid={$my_doc_id}\");";
                             echo "</script>";
                         } else {
                             //以前没打开过
@@ -1002,7 +1030,9 @@ exit;
                                     //$stmt = $PDO->prepare($query);
                                     //$newData=array($uid,$doc_id,UUID::v4(),$mbook,$paragraph,$filename,$title,$tag,time(),time(),time(),$filesize);
 
-                                    $query = "INSERT INTO fileindex ('id',
+                                    $query = "INSERT INTO "._TABLE_FILEINDEX_." (
+                                                'id',
+                                                'uid',
 												'parent_id',
 												'user_id',
 												'book',
@@ -1017,13 +1047,13 @@ exit;
 												'file_size',
 												'share',
 												'doc_info',
-												'doc_block',
-												'receive_time'
+												'doc_block'
 												)
 									VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                     $stmt = $PDO->prepare($query);
                                     $newdoc_id = UUID::v4();
                                     $newData = array(
+                                        $snowflake->id(),
                                         $newdoc_id,
                                         $doc_id,
                                         $uid,
@@ -1040,7 +1070,6 @@ exit;
                                         0,
                                         "",
                                         "",
-                                        mTime(),
                                     );
 
                                     $stmt->execute($newData);

+ 2 - 2
public/app/studio/project_load.php

@@ -4,8 +4,8 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 
 PDO_Connect(_FILE_DB_FILEINDEX_);
-$query = "select file_name from fileindex where user_id='{$_COOKIE["uid"]}' AND  id='{$_GET["id"]}'";
-$Fetch = PDO_FetchOne($query);
+$query = "SELECT file_name from "._TABLE_FILEINDEX_." where user_id=? AND  uid=?";
+$Fetch = PDO_FetchOne($query,array($_COOKIE["uid"],$_GET["id"]));
 $FileName = _DIR_USER_DOC_ . "/" . $userid . _DIR_MYDOCUMENT_ . "/" . $Fetch;
 if (file_exists($FileName)) {
     echo file_get_contents($FileName);

+ 2 - 2
public/app/studio/project_load_db.php

@@ -9,8 +9,8 @@ require_once "../public/function.php";
 $id = $_GET["id"];
 
 PDO_Connect( _FILE_DB_FILEINDEX_);
-$query = "select * from fileindex where id=" . $PDO->quote($id);
-$Fetch = PDO_FetchAll($query);
+$query = "SELECT * from "._TABLE_FILEINDEX_." where uid=?";
+$Fetch = PDO_FetchAll($query,array($id));
 if (count($Fetch) > 0) {
     echo "<set>\n";
     echo $Fetch[0]["doc_info"];

+ 43 - 0
public/db/sqlite/fileindex/up.sql

@@ -0,0 +1,43 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周日 2月 6 14:17:51 2022
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:fileindex
+CREATE TABLE fileindex (
+    id           CHAR (36),
+    parent_id    CHAR (36),
+    user_id      INTEGER,
+    book         INTEGER   DEFAULT (0),
+    paragraph    INTEGER   DEFAULT (0),
+    file_name    TEXT      NOT NULL,
+    title        TEXT,
+    tag          TEXT,
+    status       INTEGER   DEFAULT (1),
+    create_time  INTEGER,
+    modify_time  INTEGER,
+    accese_time  INTEGER,
+    file_size    INTEGER,
+    share        INTEGER   DEFAULT (0),
+    doc_info     TEXT,
+    doc_block    TEXT,
+    receive_time INTEGER
+, 'channal' TEXT);
+
+-- 表:power
+CREATE TABLE power (
+    id           CHAR (36) PRIMARY KEY,
+    doc_id       CHAR (36),
+    user         CHAR (36),
+    power        INTEGER,
+    status       INTEGER,
+    create_time  INTEGER,
+    modify_time  INTEGER,
+    receive_time INTEGER
+, 'type' INTEGER DEFAULT 0);
+
+COMMIT TRANSACTION;
+PRAGMA foreign_keys = on;

+ 35 - 0
public/db/sqlite/group/up.sql

@@ -0,0 +1,35 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周六 2月 5 08:30:59 2022
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:group_info
+CREATE TABLE group_info 
+(
+    id CHAR (36) PRIMARY KEY, 
+    parent CHAR (36), 
+    name CHAR (32) NOT NULL, 
+    description TEXT, 
+    create_time INTEGER NOT NULL, 
+    status INTEGER, 
+    owner CHAR (36), 
+    'modify_time' INTEGER
+);
+
+-- 表:group_member
+CREATE TABLE group_member 
+(
+    id INTEGER PRIMARY KEY AUTOINCREMENT, 
+    user_id CHAR (36) NOT NULL, 
+    group_id INTEGER NOT NULL, 
+    power INTEGER NOT NULL DEFAULT (1), 
+    group_name CHAR (32), 
+    level INTEGER DEFAULT (0), 
+    status INTEGER DEFAULT (1)
+);
+
+COMMIT TRANSACTION;
+PRAGMA foreign_keys = on;

+ 9 - 1
public/documents/testing.md

@@ -62,4 +62,12 @@
    1. 创建[v]
    2. 删除(无)
    3. 修改[v]
-   4. 协作[v]
+   4. 协作[v]
+9. 群组
+   1. 创建[v] (不允许建立同名群组)
+   2. 删除[v] (同时删除共享资源链接)
+   3. 修改(无)
+   4. 加成员[v]
+   5. 删除成员[v] (只有群主可以删除其他成员)
+   6. 分享资源到这个群组
+10. 

+ 9 - 0
v1/scripts/install4.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+date
+
+php ./migrations/20220205084100_group_info_copy.php
+php ./migrations/20220205092400_group_member_copy.php
+
+php ./migrations/20220206143600_fileindex_copy.php
+date

+ 181 - 0
v1/scripts/migrations/20220205084100_group_info_copy.php

@@ -0,0 +1,181 @@
+<?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_GROUP_;#源数据库
+$src_table = _SQLITE_TABLE_GROUP_INFO_;#源表名
+
+$dest_db = _PG_DB_GROUP_;#目标数据库
+$dest_table = _PG_TABLE_GROUP_INFO_;#目标表名
+
+fwrite(STDOUT,"migarate group info".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,
+									uid,
+									name,
+									description,
+									status,
+									owner,
+									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;
+$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["name"])){
+		fwrite(STDERR,time().",error,name is empty {$srcData["id"]}".PHP_EOL);
+		continue;
+	}
+
+    $srcData["status"] = 30;
+
+    if(empty($srcData["modify_time"])){
+        $srcData["modify_time"] = $srcData["create_time"];
+    }
+
+    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 uid = ? ";
+	$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["id"],
+			$srcData["name"],
+			$srcData["description"],
+			$srcData["status"],
+			$srcData["owner"],
+			$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);
+
+
+
+

+ 170 - 0
v1/scripts/migrations/20220205092400_group_member_copy.php

@@ -0,0 +1,170 @@
+<?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_GROUP_;#源数据库
+$src_table = _SQLITE_TABLE_GROUP_MEMBER_;#源表名
+
+$dest_db = _PG_DB_GROUP_;#目标数据库
+$dest_table = _PG_TABLE_GROUP_MEMBER_;#目标表名
+
+fwrite(STDOUT,"migarate group member ".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,
+									user_id,
+									group_id,
+									group_name,
+									power,
+									level,
+									status,
+									created_at,
+									updated_at) 
+									VALUES (? , ? , ? , ?, ? , ? ,?  , now() , now() )";
+$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;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    $queryExist = "SELECT *  FROM ".$dest_table." where user_id=? and group_id=? ";
+    $stmtExist = $PDO_DEST->prepare($queryExist);
+    $stmtExist->execute([$srcData["user_id"],$srcData["group_id"]]);
+    $isExist = $stmtExist->fetch(PDO::FETCH_ASSOC);
+	if($isExist){
+        echo "record is existed id=".$srcData['id'].PHP_EOL;
+        continue;
+    }
+
+{
+    if($srcData["user_id"]=='visuddhinanda'){
+		$srcData["user_id"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+    if($srcData["user_id"]=='test7'){
+		$srcData["user_id"] = '6bd2f4d7-d970-419c-8ee5-f4bac42f4bc1';
+	}
+    if($srcData["user_id"]=='Dhammadassi'){
+		$srcData["user_id"] = 'd8538ebd-d369-4777-b99a-3ccb1aff8bfc';
+	}
+    if($srcData["user_id"]=='pannava'){
+		$srcData["user_id"] = '4db550c4-bc1b-43f2-a518-2740cb478f37';
+	}
+    if($srcData["user_id"]=='NST'){
+		$srcData["user_id"] = '5c23e629-56a3-48e9-97c7-2af73b59c3b9';
+	}
+    if($srcData["user_id"]=='viranyani'){
+		$srcData["user_id"] = 'C1AB2ABF-EAA8-4EEF-B4D9-3854321852B4';
+	}
+    if($srcData["user_id"]=='test6'){
+		$srcData["user_id"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["user_id"]=='test28'){
+		$srcData["user_id"] = 'df0ad9bc-c0cd-4cd9-af05-e43d23ed57f0';
+	}
+	if($srcData["user_id"]=='290fd808-2f46-4b8c-b300-0367badd67ed'){
+		$srcData["user_id"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["user_id"]=='BA837178-9ABD-4DD4-96A0-D2C21B756DC4'){
+		$srcData["user_id"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+	$stmtUser->execute(array($srcData["user_id"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["user_id"]}".PHP_EOL);
+		continue;
+	}
+}
+
+
+	if(strlen($srcData["user_id"])>36){
+		fwrite(STDERR,time().",error,user id too long {$srcData["user_id"]}".PHP_EOL);
+		continue;	
+	}
+
+	#插入目标表
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["user_id"],
+			$srcData["group_id"],
+			$srcData["group_name"],
+			$srcData["power"],
+			$srcData["level"],
+			$srcData["status"]
+		);
+    try{
+        $stmtDEST->execute($commitData);
+    }catch (Exception $e) {
+        echo "Failed: " . $e->getMessage();
+    }
+	
+
+	$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);
+
+
+
+

+ 188 - 0
v1/scripts/migrations/20220206143600_fileindex_copy.php

@@ -0,0 +1,188 @@
+<?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_FILEINDEX_;#源数据库
+$src_table = _SQLITE_TABLE_FILEINDEX_;#源表名
+
+$dest_db = _PG_DB_FILEINDEX_;#目标数据库
+$dest_table = _PG_TABLE_FILEINDEX_;#目标表名
+
+fwrite(STDOUT,"migarate file index".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,
+									uid,
+									parent_id,
+									user_id,
+									book,
+									paragraph,
+									channal,
+									file_name,
+									title,
+									tag,
+									status,
+									file_size,
+									share,
+									doc_info,
+									doc_block,
+									create_time,
+									modify_time,
+									accese_time,
+									accesed_at,
+									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 id = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    $queryExist = "SELECT *  FROM ".$dest_table." where uid=? ";
+    $stmtExist = $PDO_DEST->prepare($queryExist);
+    $stmtExist->execute([$srcData["id"]]);
+    $isExist = $stmtExist->fetch(PDO::FETCH_ASSOC);
+	if($isExist){
+        continue;
+    }
+
+	$stmtUser->execute(array($srcData["user_id"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["user_id"]}".PHP_EOL);
+		continue;
+	}
+
+    if(empty($srcData["doc_block"]) ){
+		fwrite(STDERR,time().",error, doc_block is empty {$srcData["id"]}".PHP_EOL);
+        fputcsv($fpError,$srcData);
+		continue;
+	}
+    if(empty($srcData["book"]) ){
+        $srcData["book"] = 0;
+		fwrite(STDERR,time().",error, book is empty {$srcData["id"]}".PHP_EOL);
+        fputcsv($fpError,array('book is empty',$srcData["id"]));
+	}
+    if(empty($srcData["paragraph"]) ){
+        $srcData["paragraph"] = 0;
+		fwrite(STDERR,time().",error, paragraph is empty {$srcData["id"]}".PHP_EOL);
+        fputcsv($fpError,array('paragraph is empty',$srcData["id"]));
+	}
+    if(empty($srcData["modify_time"])){
+        $srcData["modify_time"] = $srcData["create_time"];
+    }
+
+    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 uid = ? ";
+	$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["id"],
+			$srcData["parent_id"],
+			$srcData["user_id"],
+			$srcData["book"],
+			$srcData["paragraph"],
+			$srcData["channal"],
+			$srcData["file_name"],
+			$srcData["title"],
+			$srcData["tag"],
+			$srcData["status"],
+			$srcData["file_size"],
+			$srcData["share"],
+			$srcData["doc_info"],
+			$srcData["doc_block"],
+			$srcData["create_time"],
+			$srcData["modify_time"],
+			$srcData["accese_time"],
+			$created_at,
+			$updated_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);
+
+
+
+