Skip to content

Commit dcf6a5a

Browse files
committed
提交代码
1 parent 5c739db commit dcf6a5a

File tree

4 files changed

+54
-30
lines changed

4 files changed

+54
-30
lines changed

app/Http/Controllers/Admin/ConfigController.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function saveWebsite(Request $request)
209209
];
210210
}
211211

212-
$this->modifyEnv($data);
212+
Helper::modifyEnv($data);
213213
}
214214

215215
$getResult = Config::where('name',$key)->update(['value'=>$value]);
@@ -604,31 +604,4 @@ public function changeMultiStatus(Request $request)
604604
return $this->error('操作失败!');
605605
}
606606
}
607-
608-
/**
609-
* 改变env文件
610-
*
611-
* @param Request $request
612-
* @return Response
613-
*/
614-
function modifyEnv(array $data)
615-
{
616-
$envPath = base_path() . DIRECTORY_SEPARATOR . '.env';
617-
618-
$contentArray = collect(file($envPath, FILE_IGNORE_NEW_LINES));
619-
620-
$contentArray->transform(function ($item) use ($data){
621-
foreach ($data as $key => $value){
622-
if(Str::contains($item, $key)){
623-
return $key . '=' . $value;
624-
}
625-
}
626-
627-
return $item;
628-
});
629-
630-
$content = implode($contentArray->toArray(), "\n");
631-
632-
\File::put($envPath, $content);
633-
}
634607
}

app/Http/Controllers/Admin/ConsoleController.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function update(Request $request)
152152
$result['app_version'] = config('app.version');
153153
$result['repository'] = $repository;
154154

155-
$result['can_update'] = true;
155+
$result['can_update'] = false;
156156

157157
if(isset($repository['name'])) {
158158
if($repository['name'] != $result['app_version']) {
@@ -226,7 +226,7 @@ public function updateFile(Request $request)
226226

227227
$path = storage_path('app/').'public/uploads/files/fullstack-backend-'.$version;
228228

229-
Helper::copyFileToDir($path,base_path());
229+
Helper::copyDirToDir($path,base_path());
230230

231231
return $this->success('程序更新成功!');
232232
}
@@ -245,4 +245,27 @@ public function updateDatabase(Request $request)
245245
return $this->error('数据库更新失败!',$result);
246246
}
247247
}
248+
249+
/**
250+
* 完成,更新程序版本
251+
* @author tangtanglove <[email protected]>
252+
*/
253+
public function finish(Request $request)
254+
{
255+
$version = $request->get('version');
256+
257+
$data = [
258+
'APP_VERSION' => $version
259+
];
260+
261+
Helper::modifyEnv($data);
262+
263+
$result = Artisan::call('config:clear');
264+
265+
if($result !== false) {
266+
return $this->success('更新成功!');
267+
} else {
268+
return $this->error('更新失败!');
269+
}
270+
}
248271
}

app/Services/Helper.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,4 +1809,31 @@ static function token($request)
18091809
$authorizations = explode(' ',$authorization);
18101810
return $authorizations[1];
18111811
}
1812+
1813+
/**
1814+
* 改变env文件
1815+
*
1816+
* @param Request $request
1817+
* @return Response
1818+
*/
1819+
static function modifyEnv(array $data)
1820+
{
1821+
$envPath = base_path() . DIRECTORY_SEPARATOR . '.env';
1822+
1823+
$contentArray = collect(file($envPath, FILE_IGNORE_NEW_LINES));
1824+
1825+
$contentArray->transform(function ($item) use ($data){
1826+
foreach ($data as $key => $value){
1827+
if(Str::contains($item, $key)){
1828+
return $key . '=' . $value;
1829+
}
1830+
}
1831+
1832+
return $item;
1833+
});
1834+
1835+
$content = implode($contentArray->toArray(), "\n");
1836+
1837+
\File::put($envPath, $content);
1838+
}
18121839
}

routes/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Route::get('admin/console/extract', 'Admin\\ConsoleController@extract')->name('api/admin/console/extract');
3131
Route::get('admin/console/updateFile', 'Admin\\ConsoleController@updateFile')->name('api/admin/console/updateFile');
3232
Route::get('admin/console/updateDatabase', 'Admin\\ConsoleController@updateDatabase')->name('api/admin/console/updateDatabase');
33+
Route::get('admin/console/finish', 'Admin\\ConsoleController@finish')->name('api/admin/console/finish');
3334

3435
Route::any('admin/account/info', 'Admin\\AccountController@info')->name('api/admin/account/info');
3536
Route::post('admin/account/profile', 'Admin\\AccountController@profile')->name('api/admin/account/profile');

0 commit comments

Comments
 (0)