canyin-project/ybcy/commands/HelloController.php
2024-11-01 16:07:54 +08:00

115 lines
4.1 KiB
PHP

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\commands;
use yii;
use yii\console\Controller;
use yii\console\ExitCode;
/**
* This command echoes the first argument that you have entered.
*
* This command is provided as an example for you to learn how to create console commands.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class HelloController extends Controller
{
/**
* This command echoes what you have entered as the message.
* @param string $message the message to be echoed.
* @return int Exit code
*/
public function actionIndex($message = 'hello world')
{
$cache = \Yii::$app->cache;
$cache->set('cronlock', 'isRun');
$res=$cache->get('cronlock');
print_R($res);die;
echo $message . "\n";
return ExitCode::OK;
}
//制作系统基本版本json
public function actionOriginalVersion(){
$res=scanRoot();
//file_put_contents(Yii::$app->basePath.'/web/oldSoft.lock.json', json_encode($res));
$datalist=array_keys($res);
if(file_exists(Yii::$app->basePath.'/web/upgraded/upgraded.zip')){
unlink(Yii::$app->basePath.'/web/upgraded/upgraded.zip');
}
addFileToZip($datalist,Yii::$app->basePath.'/web/upgraded/','upgraded.zip');
return ExitCode::OK;
}
//制作应用基础版本json文件
public function actionChannelVersion(){
$res=channelScanRoot();
//file_put_contents(Yii::$app->basePath.'/web/channel/channel_old.lock.json', json_encode($res));
$datalist=array_keys($res);
if(file_exists(Yii::$app->basePath.'/web/channel/channel.zip')){
unlink(Yii::$app->basePath.'/web/channel/channel.zip');
}
addFileToZip($datalist,Yii::$app->basePath.'/web/channel/','channel.zip');
return ExitCode::OK;
}
//遍历项目目录获取更新和删除的文件存储到版本更新json文件中
public function actionUpgradedVersion(){
$path =Yii::$app->basePath;
$res=scanRoot();
//var_dump($res);die;
//更新最新的版本json配置文件
file_put_contents($path.'/web/newSoft.lock.json', json_encode($res));
$storage_file=$path.'/web/upgraded/';//升级包目录
// if(!is_dir($storage_file)){
// mkdir($storage_file);
// chmod($storage_file,0755);
// }
// $storage_json=$path.'/web/upgraded/oldSoft.lock.json';//升级包json文件
// if(!file_exists($storage_json)){
// touch($storage_json);
// chmod($storage_json,0755);
// file_put_contents($storage_json, json_encode($res));
// }
$oldFile = json_decode(file_get_contents($path . '/web/oldSoft.lock.json'), true);
$newFile = json_decode(file_get_contents($path . '/web/newSoft.lock.json'), true);
$data['del'] = array_keys(array_diff_key($oldFile, $newFile));
$data['change'] = array_keys(array_diff_assoc($newFile, $oldFile));
//var_dump($data['change']);die;
//指定文件压缩制作升级压缩包文件
$filename= $storage_file."upgraded.zip";
zipFile($data['change'],$filename);
return ExitCode::OK;
}
public function actionScanRoot(){
$path =Yii::$app->basePath.'/';
$oldFile = json_decode(file_get_contents($path . 'oldSoft.lock.json'), true);
$newFile = json_decode(file_get_contents($path . 'newSoft.lock.json'), true);
$data['del'] = array_keys(array_diff_key($oldFile, $newFile));
$data['change'] = array_keys(array_diff_assoc($newFile, $oldFile));
// foreach ($data['del'] as $v){
// if(file_exists($path.$v)){
// unlink($path.$v);
// }
// }
print_R($data['change']);die;
// zipFile($data['change']);
// print_R($data);die;
//
//
//
// $res=scanRoot();
// file_put_contents(Yii::$app->basePath.'/2.0soft.lock.json', json_encode($res));
return ExitCode::OK;
}
}