77use ModStart \Core \Dao \ModelManageUtil ;
88use ModStart \Core \Dao \ModelUtil ;
99use ModStart \Core \Exception \BizException ;
10+ use ModStart \Core \Util \ArrayUtil ;
1011use ModStart \Core \Util \FileUtil ;
1112use ModStart \Module \ModuleManager ;
1213use Module \Cms \Provider \Theme \CmsThemeProvider ;
@@ -31,16 +32,20 @@ public static function listBackups()
3132 if (empty ($ json ['config ' ])) {
3233 $ json ['config ' ] = [];
3334 }
35+ $ moduleInfo = ModuleManager::getModuleBasic ($ theme ->name ());
3436 $ results [] = [
3537 'module ' => $ theme ->name (),
38+ 'moduleInfo ' => $ moduleInfo ,
3639 'root ' => 'module/ ' . $ theme ->name () . '/Backup ' ,
3740 'filename ' => $ file ['filename ' ],
41+ 'filemtime ' => filemtime ($ file ['pathname ' ]),
3842 'size ' => $ file ['size ' ],
3943 'tables ' => array_keys ($ json ['structure ' ]),
4044 'config ' => $ json ['config ' ],
4145 ];
4246 }
4347 }
48+ $ results = ArrayUtil::sortByKey ($ results , 'filemtime ' , 'desc ' );
4449 return $ results ;
4550 }
4651
@@ -50,7 +55,7 @@ public static function restoreBackup($backup)
5055 BizException::throwsIf ('备份文件损坏 ' , empty ($ backup ['backup ' ]));
5156 $ tableBackupBatch = '_del_ ' . date ('Ymd_His_ ' );
5257 foreach ($ backup ['structure ' ] as $ table => $ structure ) {
53- if (!self ::isCmsTable ($ table )) {
58+ if (!self ::isCmsTable ($ table ) && ! self :: isCmsBackupTable ( $ table ) ) {
5459 continue ;
5560 }
5661 if (ModelManageUtil::hasTable ($ table )) {
@@ -60,7 +65,7 @@ public static function restoreBackup($backup)
6065 ModelManageUtil::statement ($ structure );
6166 }
6267 foreach ($ backup ['backup ' ] as $ table => $ data ) {
63- if (!self ::isCmsTable ($ table )) {
68+ if (!self ::isCmsTable ($ table ) && ! self :: isCmsBackupTable ( $ table ) ) {
6469 continue ;
6570 }
6671 ModelUtil::insertAll ($ table , $ data , false );
@@ -73,6 +78,65 @@ public static function restoreBackup($backup)
7378 }
7479 }
7580
81+ public static function mergeConfigTitle (&$ configs )
82+ {
83+ $ titleMap = [
84+ '/^Cms_/ ' => 'CMS配置 ' ,
85+ '/^CmsTheme.*?/ ' => '主题配置 ' ,
86+ ];
87+ foreach ($ configs as $ k => $ v ) {
88+ foreach ($ titleMap as $ pattern => $ title ) {
89+ if (preg_match ($ pattern , $ v ['key ' ])) {
90+ $ configs [$ k ]['title ' ] = $ title ;
91+ break ;
92+ }
93+ }
94+ }
95+ }
96+
97+ public static function mergeTableTitle (&$ tables )
98+ {
99+ $ titleMap = [
100+ '/^banner$/ ' => '通用轮播 ' ,
101+ '/^partner$/ ' => '友情链接 ' ,
102+ '/^nav$/ ' => '通用导航 ' ,
103+ '/^content_block$/ ' => '内容区块 ' ,
104+ '/^cms_model$/ ' => 'CMS模型 ' ,
105+ '/^cms_model_field$/ ' => 'CMS模型字段 ' ,
106+ '/^cms_cat$/ ' => 'CMS栏目 ' ,
107+ '/^cms_content$/ ' => 'CMS内容主表 ' ,
108+ '/^cms_m_.*?$/ ' => 'CMS内容副表 ' ,
109+ ];
110+ foreach ($ tables as $ k => $ v ) {
111+ foreach ($ titleMap as $ pattern => $ title ) {
112+ if (preg_match ($ pattern , $ v ['name ' ])) {
113+ $ tables [$ k ]['title ' ] = $ title ;
114+ break ;
115+ }
116+ }
117+ }
118+ }
119+
120+ public static function listBackupConfigs ()
121+ {
122+ $ configs = modstart_config ()->all ();
123+ $ buildIns = [
124+ '/^Cms_/ ' ,
125+ '/^CmsTheme.*?/ ' ,
126+ ];
127+ $ configs = array_filter ($ configs , function ($ o ) use ($ buildIns ) {
128+ foreach ($ buildIns as $ pattern ) {
129+ if (preg_match ($ pattern , $ o ['key ' ])) {
130+ return true ;
131+ }
132+ }
133+ return false ;
134+ });
135+ CmsBackupUtil::mergeConfigTitle ($ configs );
136+ $ configs = ArrayUtil::sortByKey ($ configs , 'key ' );
137+ return array_values ($ configs );
138+ }
139+
76140 public static function listBackupTables ()
77141 {
78142 $ tables = ModelManageUtil::listTables ();
@@ -101,7 +165,20 @@ public static function listBackupTables()
101165 ];
102166 }
103167 }
104- return $ tables ;
168+ self ::mergeTableTitle ($ tables );
169+ $ tables = ArrayUtil::sortByKey ($ tables , 'name ' );
170+ return array_values ($ tables );
171+ }
172+
173+ public static function isCmsBackupTable ($ table )
174+ {
175+ $ tables = [
176+ 'banner ' ,
177+ 'partner ' ,
178+ 'nav ' ,
179+ 'content_block ' ,
180+ ];
181+ return in_array ($ table , $ tables );
105182 }
106183
107184 public static function isCmsTable ($ table )
0 commit comments