Skip to content

Commit a6f5147

Browse files
committed
!410 - Minor bug fixes. Added proper class name for Gitea Repos. Category and Provider will be extracted from the class given in the json file. All Api client services are going to be in \\Apis\\ class. followed by {Category}\\{Provider}\\Api_Class_Name.
1 parent f93d7c7 commit a6f5147

File tree

5 files changed

+108
-57
lines changed

5 files changed

+108
-57
lines changed

apps/Core/Components/System/Api/Client/Services/ServicesComponent.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ public function viewAction()
5757
//Check if provider class exists
5858
if (!$this->apiPackage->useApi([
5959
'config' =>
60-
['category' => $this->getData()['category'],
61-
'provider' => $this->getData()['provider'],
62-
'checkOnly' => true//Set this to check if the API exists and can be instantiated.
60+
[
61+
'category' => $this->getData()['category'],
62+
'provider' => $this->getData()['provider'],
63+
'checkOnly' => true//Set this to check if the API exists and can be instantiated.
6364
]
6465
])
6566
) {

apps/Core/Packages/Devtools/Modules/DevtoolsModules.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,15 @@ public function getAvailableApis($getAll = false, $returnApis = true)
22162216
if (count($apisArr) > 0) {
22172217
foreach ($apisArr as $api) {
22182218
if ($api['category'] === 'repos') {
2219-
$useApi = $this->basepackages->apiClientServices->useApi($api['id'], true);
2219+
$useApi = $this->basepackages->apiClientServices->useApi([
2220+
'config' =>
2221+
[
2222+
'id' => $api['id'],
2223+
'category' => $api['category'],
2224+
'provider' => $api['provider'],
2225+
'checkOnly' => true//Set this to check if the API exists and can be instantiated.
2226+
]
2227+
]);
22202228

22212229
if ($useApi) {
22222230
$apiConfig = $useApi->getApiConfig();
@@ -2232,6 +2240,7 @@ public function getAvailableApis($getAll = false, $returnApis = true)
22322240
if ($returnApis) {
22332241
return $apis;
22342242
}
2243+
22352244
return $apisArr;
22362245
}
22372246
}

apps/Core/Views/Default/html/devtools/modules/module.html

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,9 +1972,9 @@
19721972
keys =
19731973
[
19741974
{
1975-
'databasetype' : {
1976-
'id' : 'databasetype',
1977-
'text' : 'Database Type'
1975+
'dev' : {
1976+
'id' : 'dev',
1977+
'text' : 'Development Mode?'
19781978
}
19791979
},
19801980
{
@@ -1983,6 +1983,18 @@
19831983
'text' : 'Debug Enabled?'
19841984
}
19851985
},
1986+
{
1987+
'auto_off_debug' : {
1988+
'id' : 'auto_off_debug',
1989+
'text' : 'Auto Off Debug'
1990+
}
1991+
},
1992+
{
1993+
'databasetype' : {
1994+
'id' : 'databasetype',
1995+
'text' : 'Database Type'
1996+
}
1997+
},
19861998
{
19871999
'cache-enabled' : {
19882000
'id' : 'cache-enabled',
@@ -2001,6 +2013,12 @@
20012013
'text' : 'Cache Service'
20022014
}
20032015
},
2016+
{
2017+
'security-sso' : {
2018+
'id' : 'security-sso',
2019+
'text' : 'Single Sign On'
2020+
}
2021+
},
20042022
{
20052023
'security-passwordWorkFactor' : {
20062024
'id' : 'security-passwordWorkFactor',
@@ -2353,12 +2371,12 @@
23532371
}
23542372
} else if (dataCollectionSectionForm['vars']['module_type'] === 'core') {
23552373
switch (key) {
2356-
case 'databasetype' :
2357-
type = 'text';
2374+
case 'dev' :
2375+
type = 'boolean';
23582376
settings = '';
23592377

2360-
if (dataCollectionSectionForm['vars']['moduleSettings']['databasetype']) {
2361-
settings = dataCollectionSectionForm['vars']['moduleSettings']['databasetype'];
2378+
if (dataCollectionSectionForm['vars']['moduleSettings']['dev']) {
2379+
settings = dataCollectionSectionForm['vars']['moduleSettings']['dev'];
23622380
}
23632381

23642382
break;
@@ -2370,6 +2388,24 @@
23702388
settings = dataCollectionSectionForm['vars']['moduleSettings']['debug'];
23712389
}
23722390

2391+
break;
2392+
case 'auto_off_debug' :
2393+
type = 'text';
2394+
settings = '';
2395+
2396+
if (dataCollectionSectionForm['vars']['moduleSettings']['auto_off_debug']) {
2397+
settings = dataCollectionSectionForm['vars']['moduleSettings']['auto_off_debug'];
2398+
}
2399+
2400+
break;
2401+
case 'databasetype' :
2402+
type = 'text';
2403+
settings = '';
2404+
2405+
if (dataCollectionSectionForm['vars']['moduleSettings']['databasetype']) {
2406+
settings = dataCollectionSectionForm['vars']['moduleSettings']['databasetype'];
2407+
}
2408+
23732409
break;
23742410
case 'cache-enabled' :
23752411
type = 'boolean';
@@ -2397,6 +2433,15 @@
23972433
settings = dataCollectionSectionForm['vars']['moduleSettings']['cache']['service'];
23982434
}
23992435

2436+
break;
2437+
case 'security-sso' :
2438+
type = 'boolean';
2439+
settings = '';
2440+
2441+
if (dataCollectionSectionForm['vars']['moduleSettings']['security']['sso']) {
2442+
settings = dataCollectionSectionForm['vars']['moduleSettings']['security']['sso'];
2443+
}
2444+
24002445
break;
24012446
case 'security-passwordWorkFactor' :
24022447
type = 'text';
@@ -2633,15 +2678,25 @@
26332678
}
26342679
} else if (dataCollectionSectionForm['vars']['module_type'] === 'core') {
26352680
switch (key) {
2636-
case 'databasetype' :
2637-
dataCollectionSectionForm['vars']['moduleSettings']['databasetype']
2681+
case 'dev' :
2682+
dataCollectionSectionForm['vars']['moduleSettings']['dev']
26382683
= $('#{{componentId}}-{{sectionId}}-settings-' + fieldType).val();
26392684

26402685
break;
26412686
case 'debug' :
26422687
dataCollectionSectionForm['vars']['moduleSettings']['debug']
26432688
= $('#{{componentId}}-{{sectionId}}-settings-' + fieldType).val();
26442689

2690+
break;
2691+
case 'auto_off_debug' :
2692+
dataCollectionSectionForm['vars']['moduleSettings']['auto_off_debug']
2693+
= $('#{{componentId}}-{{sectionId}}-settings-' + fieldType).val();
2694+
2695+
break;
2696+
case 'databasetype' :
2697+
dataCollectionSectionForm['vars']['moduleSettings']['databasetype']
2698+
= $('#{{componentId}}-{{sectionId}}-settings-' + fieldType).val();
2699+
26452700
break;
26462701
case 'cache-enabled' :
26472702
dataCollectionSectionForm['vars']['moduleSettings']['cache']['enabled']
@@ -2657,6 +2712,11 @@
26572712
dataCollectionSectionForm['vars']['moduleSettings']['cache']['service']
26582713
= $('#{{componentId}}-{{sectionId}}-settings-' + fieldType).val();
26592714

2715+
break;
2716+
case 'security-sso' :
2717+
dataCollectionSectionForm['vars']['moduleSettings']['security']['sso']
2718+
= $('#{{componentId}}-{{sectionId}}-settings-' + fieldType).val();
2719+
26602720
break;
26612721
case 'security-passwordWorkFactor' :
26622722
dataCollectionSectionForm['vars']['moduleSettings']['security']['passwordWorkFactor']
@@ -2809,12 +2869,16 @@
28092869
e.preventDefault();
28102870

28112871
var found = false;
2812-
28132872
if (label === 'core') {
28142873
dataCollectionSectionForm['vars']['moduleDependencies'][label] = { };
28152874
dataCollectionSectionForm['vars']['moduleDependencies'][label]['name'] = moduleData['name'];
28162875
dataCollectionSectionForm['vars']['moduleDependencies'][label]['version'] = moduleData['version'];
28172876
dataCollectionSectionForm['vars']['moduleDependencies'][label]['repo'] = moduleData['repo'];
2877+
} else if (label === 'apptypes') {
2878+
dataCollectionSectionForm['vars']['moduleDependencies']['apptype'] = { };
2879+
dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['name'] = moduleData['name'];
2880+
dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['version'] = moduleData['version'];
2881+
dataCollectionSectionForm['vars']['moduleDependencies']['apptype']['repo'] = moduleData['repo'];
28182882
} else if (label === 'external') {
28192883
if (dataCollectionSectionForm['vars']['moduleDependencies']['external'].length === 0) {
28202884
dataCollectionSectionForm['vars']['moduleDependencies']['external'] = { };
@@ -2874,6 +2938,8 @@
28742938

28752939
if (label === 'core') {
28762940
dataCollectionSectionForm['vars']['moduleDependencies'][label] = { };
2941+
} else if (label === 'apptypes') {
2942+
dataCollectionSectionForm['vars']['moduleDependencies']['apptype'] = { };
28772943
} else if (label === 'external') {
28782944
delete dataCollectionSectionForm['vars']['moduleDependencies'][label][$('#{{componentId}}-{{sectionId}}-dependencies-external').val()];
28792945
} else {

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/ApiClientServices.php

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function registerApiCategories()
9292
$this->apiCategories[$category]['childs'] = [];
9393
}
9494

95-
$provider = strtolower($this->helper->last($api['class']));
95+
$provider = strtolower($api['class'][$this->helper->lastKey($api['class']) - 1]);
9696

9797
if (!isset($this->apiCategories[$category]['childs'][$provider])) {
9898
$this->apiCategories[$category]['childs'][$provider] = [];
@@ -320,7 +320,11 @@ public function useApi($data)//or ID (integer/string)
320320
}
321321
}
322322
} else if (isset($data['config'])) {
323-
$this->apiConfig = $data['config'];
323+
if (isset($data['config']['id'])) {
324+
$this->apiConfig = $this->getApiById((int) $data['config']['id']);
325+
} else {
326+
$this->apiConfig = $data['config'];
327+
}
324328
}
325329
} else if (is_int($data) || is_string($data)) {
326330
$this->apiConfig = $this->getApiById((int) $data);
@@ -350,22 +354,31 @@ protected function initApi(array $config = null)
350354
$apiClass = $this->getApiClass($config['category'], $config['provider']);
351355

352356
if ($apiClass) {
353-
return (new $apiClass())->init($config, $this);
357+
try {
358+
return (new $apiClass())->init($config, $this);
359+
} catch (\Exception $e) {
360+
throw $e;
361+
}
354362
}
355363

356364
return false;
357365
}
358366

359367
public function getApiClass($category, $provider, $basepackages = true)
360368
{
369+
//Class of API defined in the package defined the location of the API and its category and provider
370+
//Example: WhateverLocation\\Apis\\{Category}\\{Provider}\\API_CLASS
371+
$basepackagesApis = $this->modules->packages->getPackagesForCategory('basepackages_apis');
361372
$apis = $this->modules->packages->getPackagesForCategory('apis');
362373

374+
$apis = array_merge($basepackagesApis, $apis);
375+
363376
if ($apis && is_array($apis) && count($apis) > 0) {
364377
foreach ($apis as $apiKey => $api) {
365378
$api['class'] = explode('\\', $api['class']);
366379

367380
$apiCategory = strtolower($api['class'][$this->helper->lastKey($api['class']) - 2]);
368-
$apiProvider = strtolower($this->helper->last($api['class']));
381+
$apiProvider = strtolower($api['class'][$this->helper->lastKey($api['class']) - 1]);
369382

370383
if ($category === $apiCategory &&
371384
$provider === $apiProvider
@@ -416,44 +429,6 @@ function($api) use ($category) {
416429
return $filter;
417430
}
418431

419-
public function getApiByProvider($provider, $inuse = null)
420-
{
421-
$this->getAll();
422-
423-
if (isset($inuse)) {
424-
if ($inuse === true) {
425-
$inUse = '1';
426-
} else {
427-
$inUse = '0'|null;
428-
}
429-
$filter =
430-
$this->model->filter(
431-
function($api) use ($provider, $inUse) {
432-
$api = $this->getApiById($api->id);
433-
434-
if ($api['provider'] === strtolower($provider) &&
435-
$api['in_use'] == $inUse
436-
) {
437-
return $api;
438-
}
439-
}
440-
);
441-
} else {
442-
$filter =
443-
$this->model->filter(
444-
function($api) use ($provider) {
445-
$api = $this->getApiById($api->id);
446-
447-
if ($api['provider'] === strtolower($provider)) {
448-
return $api;
449-
}
450-
}
451-
);
452-
}
453-
454-
return $filter;
455-
}
456-
457432
protected function encryptPassToken(array $data)
458433
{
459434
if (isset($data['auth_type'])) {

system/Base/Providers/BasepackagesServiceProvider/Packages/ApiClientServices/Apis/Repos/Gitea/ApisReposGitea.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use System\Base\Providers\BasepackagesServiceProvider\Packages\ApiClientServices\Apis\Repos\Repos;
66

7-
class ApisRepoGitea extends Repos
7+
class ApisReposGitea extends Repos
88
{
99
public function init($apiConfig = null, $api = null, $httpOptions = null)
1010
{

0 commit comments

Comments
 (0)