From 96b899b5271cc19197f97ee5e7dae1a043563948 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 4 Sep 2023 14:48:55 +0800 Subject: [PATCH] * Replace array_column to helper::arrayColumn, compatibility with low version object arrays. --- module/block/control.php | 8 ++++---- module/cne/model.php | 12 ++++++------ module/execution/control.php | 2 +- module/instance/model.php | 18 +++++++++--------- module/mr/model.php | 4 ++-- module/my/model.php | 2 +- module/program/control.php | 2 +- module/repo/control.php | 4 ++-- module/repo/zen.php | 2 +- module/space/control.php | 2 +- module/space/model.php | 2 +- module/space/view/browse.html.php | 2 +- module/store/control.php | 2 +- module/store/model.php | 4 ++-- module/store/ui/appview.html.php | 2 +- module/store/view/appview.html.php | 2 +- module/story/model.php | 2 +- module/system/ui/dashboard.html.php | 2 +- module/system/view/instancesblock.html.php | 2 +- module/task/control.php | 4 ++-- module/upgrade/model.php | 2 +- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/module/block/control.php b/module/block/control.php index 3bbfb2f073..b91a1fa924 100755 --- a/module/block/control.php +++ b/module/block/control.php @@ -362,7 +362,7 @@ class block extends control public function dynamic() { $this->view->actions = $this->loadModel('action')->getDynamic('all', 'today', 'id_desc', 30); - $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all', '', 0, array_unique(array_column($this->view->actions, 'actor'))); + $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all', '', 0, array_unique(helper::arrayColumn($this->view->actions, 'actor'))); $this->display(); } @@ -898,7 +898,7 @@ class block extends control $orderBy = isset($this->params->orderBy) ? $this->params->orderBy : 'id_desc'; $this->view->projects = $this->loadModel('project')->getOverviewList('byStatus', $type, $orderBy, $count); - $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(array_column($this->view->projects, 'PM'))); + $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(helper::arrayColumn($this->view->projects, 'PM'))); } /** @@ -1571,7 +1571,7 @@ class block extends control $projectID = $this->session->project; $this->view->actions = $this->loadModel('action')->getDynamic('all', 'all', 'id_desc', 30, 'all', $projectID); - $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(array_column($this->view->actions, 'actor'))); + $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(helper::arrayColumn($this->view->actions, 'actor'))); } /** @@ -2108,7 +2108,7 @@ class block extends control public function printDocDynamicBlock() { $this->view->actions = $this->loadModel('doc')->getDynamic(30); - $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all', '', 0, array_unique(array_column($this->view->actions, 'actor'))); + $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all', '', 0, array_unique(helper::arrayColumn($this->view->actions, 'actor'))); } /** diff --git a/module/cne/model.php b/module/cne/model.php index db44560b8a..ff9cc45a7b 100644 --- a/module/cne/model.php +++ b/module/cne/model.php @@ -50,7 +50,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $instanceList = $result->data; - return array_combine(array_column($instanceList, 'name'), $instanceList); + return array_combine(helper::arrayColumn($instanceList, 'name'), $instanceList); } /** @@ -449,7 +449,7 @@ class cneModel extends model $apiUrl = "/api/cne/statistics/app"; $result = $this->apiPost($apiUrl, $apiData, $this->config->CNE->api->headers); - if(!isset($result->code) || $result->code != 200)return array_combine(array_column($instancesMetrics, 'id'), $instancesMetrics); + if(!isset($result->code) || $result->code != 200)return array_combine(helper::arrayColumn($instancesMetrics, 'id'), $instancesMetrics); foreach($result->data as $k8sMetric) { @@ -468,7 +468,7 @@ class cneModel extends model $instancesMetrics[$k8sMetric->name]->memory->rate = $instancesMetrics[$k8sMetric->name]->memory->limit > 0 ? round($instancesMetrics[$k8sMetric->name]->memory->usage / $instancesMetrics[$k8sMetric->name]->memory->limit * 100, 2) : 0; } - return array_combine(array_column($instancesMetrics, 'id'), $instancesMetrics); + return array_combine(helper::arrayColumn($instancesMetrics, 'id'), $instancesMetrics); } /** @@ -998,7 +998,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $dbList = $result->data; - return array_combine(array_column($dbList, 'name'), $dbList); + return array_combine(helper::arrayColumn($dbList, 'name'), $dbList); } /** @@ -1062,7 +1062,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $dbList = $result->data; - return array_combine(array_column($dbList, 'name'), $dbList); + return array_combine(helper::arrayColumn($dbList, 'name'), $dbList); } /** @@ -1082,7 +1082,7 @@ class cneModel extends model if(empty($result) || $result->code != 200 || empty($result->data)) return array(); $dbList = $result->data; - return array_combine(array_column($dbList, 'name'), $dbList); + return array_combine(helper::arrayColumn($dbList, 'name'), $dbList); } /** diff --git a/module/execution/control.php b/module/execution/control.php index 34ef7f6d61..8de49168ca 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -4101,7 +4101,7 @@ class execution extends control $this->view->productID = $productID; $this->view->pager = $pager; $this->view->orderBy = $orderBy; - $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(array_column($executionStats, 'PM'))); + $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(helper::arrayColumn($executionStats, 'PM'))); $this->view->projects = array('') + $this->project->getPairsByProgram(); $this->view->status = $status; $this->view->from = $from; diff --git a/module/instance/model.php b/module/instance/model.php index b30eb38fa3..5c123d11bb 100644 --- a/module/instance/model.php +++ b/module/instance/model.php @@ -63,10 +63,10 @@ class InstanceModel extends model ->andWhere('deleted')->eq(0) ->fetchAll('id'); - $spaces = $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('id')->in(array_column($instances, 'space'))->fetchAll('id'); + $spaces = $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('id')->in(helper::arrayColumn($instances, 'space'))->fetchAll('id'); foreach($instances as $instance) $instance->spaceData = zget($spaces, $instance->space, new stdclass); - $solutionIDList = array_column($instances, 'solution'); + $solutionIDList = helper::arrayColumn($instances, 'solution'); $solutions = $this->dao->select('*')->from(TABLE_SOLUTION)->where('id')->in($solutionIDList)->fetchAll('id'); foreach($instances as $instance) $instance->solutionData = zget($solutions, $instance->solution, new stdclass); @@ -119,12 +119,12 @@ class InstanceModel extends model $spaces = $this->dao->select('*')->from(TABLE_SPACE) ->where('deleted')->eq(0) - ->andWhere('id')->in(array_column($instances, 'space')) + ->andWhere('id')->in(helper::arrayColumn($instances, 'space')) ->fetchAll('id'); foreach($instances as $instance) $instance->spaceData = zget($spaces, $instance->space, new stdclass); - $solutionIDList = array_column($instances, 'solution'); + $solutionIDList = helper::arrayColumn($instances, 'solution'); $solutions = $this->dao->select('*')->from(TABLE_SOLUTION)->where('id')->in($solutionIDList)->fetchAll('id'); foreach($instances as $instance) $instance->solutionData = zget($solutions, $instance->solution, new stdclass); @@ -143,7 +143,7 @@ class InstanceModel extends model $spaces = $this->dao->select('*')->from(TABLE_SPACE) ->where('deleted')->eq(0) - ->andWhere('id')->in(array_column($instances, 'space')) + ->andWhere('id')->in(helper::arrayColumn($instances, 'space')) ->fetchAll('id'); foreach($instances as $instance) $instance->spaceData = zget($spaces, $instance->space, new stdclass); @@ -330,7 +330,7 @@ class InstanceModel extends model ->andWhere("REPLACE(domain, '.$sysDomain', '')")->like("%.%") ->fetchAll('id'); - $spaces = $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('id')->in(array_column($instanceList, 'space'))->fetchAll('id'); + $spaces = $this->dao->select('*')->from(TABLE_SPACE)->where('deleted')->eq(0)->andWhere('id')->in(helper::arrayColumn($instanceList, 'space'))->fetchAll('id'); foreach($instanceList as $instance) $instance->spaceData = zget($spaces, $instance->space, new stdclass); @@ -1518,8 +1518,8 @@ class InstanceModel extends model $backupList = $result->data; usort($backupList, function($backup1, $backup2){ return $backup1->create_time < $backup2->create_time; }); - $accounts = array_column($backupList, 'creator'); - foreach($backupList as $backup) $accounts = array_merge($accounts, array_column($backup->restores, 'creator')); + $accounts = helper::arrayColumn($backupList, 'creator'); + foreach($backupList as $backup) $accounts = array_merge($accounts, helper::arrayColumn($backup->restores, 'creator')); $accounts = array_unique($accounts); @@ -1652,7 +1652,7 @@ class InstanceModel extends model ->fetchAll(); if(empty($instanceList)) return; - $spaceList = $this->dao->select('*')->from(TABLE_SPACE)->where('id')->in(array_column($instanceList, 'space'))->fetchAll('id'); + $spaceList = $this->dao->select('*')->from(TABLE_SPACE)->where('id')->in(helper::arrayColumn($instanceList, 'space'))->fetchAll('id'); foreach($instanceList as $instance) { diff --git a/module/mr/model.php b/module/mr/model.php index 5bf6a2a600..d0750d1421 100644 --- a/module/mr/model.php +++ b/module/mr/model.php @@ -123,7 +123,7 @@ class mrModel extends model public function getGiteaProjects($hostID = 0) { $projects = $this->loadModel('gitea')->apiGetProjects($hostID); - return array($hostID => array_column($projects, null, 'full_name')); + return array($hostID => helper::arrayColumn($projects, null, 'full_name')); } /** @@ -136,7 +136,7 @@ class mrModel extends model public function getGogsProjects($hostID = 0) { $projects = $this->loadModel('gogs')->apiGetProjects($hostID); - return array($hostID => array_column($projects, null, 'full_name')); + return array($hostID => helper::arrayColumn($projects, null, 'full_name')); } /** diff --git a/module/my/model.php b/module/my/model.php index e024d6fea8..0c1c15aaf1 100644 --- a/module/my/model.php +++ b/module/my/model.php @@ -150,7 +150,7 @@ class myModel extends model /* Sort by storyCount, get 5 records */ $products = json_decode(json_encode($products), true); - array_multisort(array_column($products, 'storyEstimateCount'), SORT_DESC, $products); + array_multisort(helper::arrayColumn($products, 'storyEstimateCount'), SORT_DESC, $products); $products = array_slice($products, 0, 5); $data = new stdClass(); diff --git a/module/program/control.php b/module/program/control.php index 343ac8c92a..8fc5c06172 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -75,7 +75,7 @@ class program extends control } /* Get PM id list. */ - $accounts = array_unique(array_column(json_decode(json_encode($programs), true), 'PM')); + $accounts = array_unique(helper::arrayColumn($programs, 'PM')); $hasProject = false; foreach($programs as $program) { diff --git a/module/repo/control.php b/module/repo/control.php index 6407cd3571..cf9de81211 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -215,7 +215,7 @@ class repo extends control $products = $this->loadModel('product')->getPairs('', 0, '', 'all'); $linkedProducts = $this->loadModel('product')->getByIdList(explode(',', $repo->product)); - $linkedProductPairs = array_combine(array_keys($linkedProducts), array_column(json_decode(json_encode($linkedProducts), true), 'name')); + $linkedProductPairs = array_combine(array_keys($linkedProducts), helper::arrayColumn($linkedProducts, 'name')); $products = $products + $linkedProductPairs; $this->view->title = $this->lang->repo->common . $this->lang->colon . $this->lang->repo->edit; @@ -1695,7 +1695,7 @@ class repo extends control $products = $postData->objectID ? $this->loadModel('product')->getProductPairsByProject($objectID) : $this->loadModel('product')->getPairs(); $linkedProducts = $this->loadModel('product')->getByIdList($postData->products); - $linkedProductPairs = array_combine(array_keys($linkedProducts), array_column($linkedProducts, 'name')); + $linkedProductPairs = array_combine(array_keys($linkedProducts), helper::arrayColumn($linkedProducts, 'name')); $products = $products + $linkedProductPairs; return print (html::select('product[]', $products, $selectedProducts, "class='form-control chosen' multiple")); diff --git a/module/repo/zen.php b/module/repo/zen.php index e896586aab..50a9917cf4 100644 --- a/module/repo/zen.php +++ b/module/repo/zen.php @@ -363,7 +363,7 @@ class repoZen extends repo else { $infos = $this->scm->ls($path, $revision); - $revisionList = array_column($infos, 'revision', 'revision'); + $revisionList = helper::arrayColumn($infos, 'revision', 'revision'); $comments = $this->repo->getHistory($repo->id, $revisionList); foreach($infos as $info) { diff --git a/module/space/control.php b/module/space/control.php index 7fe2a4638d..ee45ea6b3c 100644 --- a/module/space/control.php +++ b/module/space/control.php @@ -79,7 +79,7 @@ class space extends control /* Data sort. */ list($order, $sort) = explode('_', $orderBy); $orderInstances = json_decode(json_encode($allInstances), true); - $createdColumn = array_column($orderInstances, $order == 'id' ? 'createdAt' : $order); + $createdColumn = helper::arrayColumn($orderInstances, $order == 'id' ? 'createdAt' : $order); array_multisort($createdColumn, $sort == 'desc' ? SORT_DESC : SORT_ASC, $allInstances); /* Pager. */ diff --git a/module/space/model.php b/module/space/model.php index 0262ecd21c..45f88d7cb1 100644 --- a/module/space/model.php +++ b/module/space/model.php @@ -107,7 +107,7 @@ class spaceModel extends model $this->loadModel('store'); foreach($instances as $instance) $instance->latestVersion = $this->store->appLatestVersion($instance->appID, $instance->version); - $solutionIDList = array_column($instances, 'solution'); + $solutionIDList = helper::arrayColumn($instances, 'solution'); $solutions = $this->dao->select('*')->from(TABLE_SOLUTION)->where('id')->in($solutionIDList)->fetchAll('id'); foreach($instances as $instance) $instance->solutionData = zget($solutions, $instance->solution, new stdclass); diff --git a/module/space/view/browse.html.php b/module/space/view/browse.html.php index 429524a66c..c9f50dd162 100644 --- a/module/space/view/browse.html.php +++ b/module/space/view/browse.html.php @@ -12,7 +12,7 @@ ?> app->getModuleRoot() . '/common/view/header.html.php';?> instance->notices);?> - +