From be2d532c770166247cd8b295524766c55ac5b9b2 Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Fri, 24 Dec 2021 09:33:45 +0800 Subject: [PATCH] * Add the zentao api lib for upgrade. --- db/api/{ => 16.0}/api | 0 db/api/{ => 16.0}/apispec | 0 db/api/{ => 16.0}/apistruct | 0 db/api/{ => 16.0}/apistruct_spec | 0 db/api/{ => 16.0}/module | 0 module/api/model.php | 28 ++++++++++++++++------------ module/upgrade/model.php | 5 +++++ 7 files changed, 21 insertions(+), 12 deletions(-) rename db/api/{ => 16.0}/api (100%) rename db/api/{ => 16.0}/apispec (100%) rename db/api/{ => 16.0}/apistruct (100%) rename db/api/{ => 16.0}/apistruct_spec (100%) rename db/api/{ => 16.0}/module (100%) diff --git a/db/api/api b/db/api/16.0/api similarity index 100% rename from db/api/api rename to db/api/16.0/api diff --git a/db/api/apispec b/db/api/16.0/apispec similarity index 100% rename from db/api/apispec rename to db/api/16.0/apispec diff --git a/db/api/apistruct b/db/api/16.0/apistruct similarity index 100% rename from db/api/apistruct rename to db/api/16.0/apistruct diff --git a/db/api/apistruct_spec b/db/api/16.0/apistruct_spec similarity index 100% rename from db/api/apistruct_spec rename to db/api/16.0/apistruct_spec diff --git a/db/api/module b/db/api/16.0/module similarity index 100% rename from db/api/module rename to db/api/16.0/module diff --git a/module/api/model.php b/module/api/model.php index c68d298d30..87074079bf 100644 --- a/module/api/model.php +++ b/module/api/model.php @@ -735,16 +735,19 @@ class apiModel extends model /** * Create demo data. * + * @param string $name + * @param string $baseUrl + * @param string $version * @access public * @return int */ - public function createDemoData() + public function createDemoData($name, $baseUrl, $version) { /* Insert doclib. */ $lib = new stdclass(); $lib->type = 'api'; - $lib->name = $this->post->name; - $lib->baseUrl = $this->post->baseUrl; + $lib->name = $name; + $lib->baseUrl = $baseUrl; $lib->acl = 'private'; $lib->users = ',' . $this->app->user->account . ','; $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); @@ -753,7 +756,7 @@ class apiModel extends model /* Insert struct. */ $structMap = array(); - $structs = $this->getDemoData('apistruct'); + $structs = $this->getDemoData('apistruct', $version); foreach($structs as $struct) { $oldID = $struct->id; @@ -772,7 +775,7 @@ class apiModel extends model } /* Insert struct spec. */ - $specs = $this->getDemoData('apistruct_spec'); + $specs = $this->getDemoData('apistruct_spec', $version); foreach($specs as $spec) { unset($spec->id); @@ -784,7 +787,7 @@ class apiModel extends model } /* Insert module. */ - $modules = $this->getDemoData('module'); + $modules = $this->getDemoData('module', $version); foreach($modules as $module) { if($module->type != 'api') continue; @@ -804,7 +807,7 @@ class apiModel extends model /* Insert api. */ $this->loadModel('action'); $apiMap = array(); - $apis = $this->getDemoData('api'); + $apis = $this->getDemoData('api', $version); foreach($apis as $api) { $oldID = $api->id; @@ -826,7 +829,7 @@ class apiModel extends model } /* Insert api spec. */ - $specs = $this->getDemoData('apispec'); + $specs = $this->getDemoData('apispec', $version); foreach($specs as $spec) { unset($spec->id); @@ -844,15 +847,16 @@ class apiModel extends model } /** - * Get demo data + * Get demo data. * - * @param string $table + * @param string $table + * @param stirng $version * @access private * @return array */ - private function getDemoData($table) + private function getDemoData($table, $version) { - $file = $this->app->getAppRoot() . 'db' . DS . 'api' . DS . $table; + $file = $this->app->getAppRoot() . 'db' . DS . 'api' . DS . $version . DS . $table; return unserialize(file_get_contents($file)); } } diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 211b3c86ab..60f5422cb2 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -736,6 +736,11 @@ class upgradeModel extends model $this->updateProjectStories(); $this->updateProjectLinkedBranch(); $this->appendExec('15_7_1'); + case '16_0_beta1': + $this->saveLogs('Execute 16_0_beta1'); + $this->execSQL($this->getUpgradeFile('16.0.beta1')); + $this->loadModel('api')->createDemoData($this->lang->api->zentaoAPI, 'http://' . $_SERVER['HTTP_HOST'] . $this->app->config->webRoot . 'api.php/v1', '16.0'); + $this->appendExec('16_0_beta1'); } $this->deletePatch();