From bfd8107a73d48ccd6d0b9004e46c18fe773bda5e Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 21 Nov 2023 14:03:46 +0800 Subject: [PATCH] * Add param type for admin method. --- module/admin/control.php | 28 +++++++++++++++++++++------- module/admin/model.php | 4 ++-- module/common/model.php | 28 ++++++++++++---------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/module/admin/control.php b/module/admin/control.php index 766630e282..a2cc5d265d 100755 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -12,6 +12,26 @@ declare(strict_types=1); */ class admin extends control { + /** + * The gogs constructor. + * + * @param string $moduleName + * @param string $methodName + */ + public function __construct(string $moduleName = '', string $methodName = '') + { + parent::__construct($moduleName, $methodName); + + if(!isset($this->config->global->sn)) + { + $sn = $this->setting->computeSN(); + $this->loadModel('setting')->setItem('system.common.global.sn', $sn); + + if(!isset($this->config->global)) $this->config->global = new stdclass(); + $this->config->global->sn = $sn; + } + } + /** * 后台首页。 * Background homepage. @@ -33,22 +53,18 @@ class admin extends control if(!$community or $community == 'na') { $this->view->bind = false; - $this->view->account = false; $this->view->ignore = $community == 'na'; } else { $this->view->bind = true; - $this->view->account = $community; $this->view->ignore = false; } $this->view->title = $this->lang->admin->common; $this->view->zentaoData = $this->admin->getZentaoData(); $this->view->dateUsed = $this->admin->genDateUsed(); - $this->view->langNotCN = common::checkNotCN(); $this->view->hasInternet = $this->admin->checkInternet(); - $this->view->isIntranet = helper::isIntranet(); $this->display(); } @@ -63,9 +79,7 @@ class admin extends control { if(helper::isIntranet()) return $this->send(array('result' => 'fail')); - $hasInternet = $this->admin->checkInternet(); - - if($hasInternet) + if($this->admin->checkInternet()) { $lastSyncDate = !empty($this->config->zentaoWebsite->lastSyncDate) ? $this->config->zentaoWebsite->lastSyncDate : ''; $nextWeek = date('Y-m-d', strtotime('-7 days')); diff --git a/module/admin/model.php b/module/admin/model.php index 7218859819..804d3e6417 100755 --- a/module/admin/model.php +++ b/module/admin/model.php @@ -20,9 +20,9 @@ class adminModel extends model * @param string $url * @param string $formvars * @access public - * @return void + * @return string */ - public function postAPI($url, $formvars = '') + public function postAPI(string $url, string $formvars = ''): string { return common::http($url, $formvars); } diff --git a/module/common/model.php b/module/common/model.php index 32ad3a0762..a1aab0140e 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -3072,7 +3072,7 @@ EOF; * @access public * @return string|array */ - public static function http($url, $data = null, $options = array(), $headers = array(), $dataType = 'data', $method = 'POST', $timeout = 30, $httpCode = false, $log = true) + public static function http(string $url, string|array|null $data = null, array $options = array(), array $headers = array(), string $dataType = 'data', string $method = 'POST', int $timeout = 30, bool $httpCode = false, bool $log = true): string|array { global $lang, $app; if(!extension_loaded('curl')) @@ -3154,23 +3154,19 @@ EOF; $logFile = $app->getLogRoot() . 'saas' . $runMode . '.' . date('Ymd') . '.log.php'; if(!file_exists($logFile)) file_put_contents($logFile, ''); - $fh = fopen($logFile, 'a'); - if($fh) + $saasLog = date('Ymd H:i:s') . ': ' . $app->getURI() . "\n"; + $saasLog .= "{$requestType} url: {$url}\n"; + if(!empty($data)) $saasLog .= 'data: ' . print_r($data, true) . "\n"; + $saasLog .= 'results:' . print_r($response, true) . "\n"; + + if(!empty($errors)) { - fwrite($fh, date('Ymd H:i:s') . ': ' . $app->getURI() . "\n"); - fwrite($fh, "{$requestType} url: " . $url . "\n"); - if(!empty($data)) fwrite($fh, 'data: ' . print_r($data, true) . "\n"); - fwrite($fh, 'results:' . print_r($response, true) . "\n"); - - if(!empty($errors)) - { - fwrite($fh, 'errno: ' . $errno . "\n"); - fwrite($fh, 'errors: ' . $errors . "\n"); - fwrite($fh, 'info: ' . print_r($info, true) . "\n"); - } - - fclose($fh); + $saasLog .= "errno: {$errno}\n"; + $saasLog .= "errors: {$errors}\n"; + $saasLog .= 'info: ' . print_r($info, true) . "\n"; } + + file_put_contents($logFile, $sassLog, FILE_APPEND); } if($errors) commonModel::$requestErrors[] = $errors;