1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Canvas\Api\Controllers; |
6
|
|
|
|
7
|
|
|
use Canvas\Models\SystemModules; |
8
|
|
|
use Phalcon\Http\Response; |
|
|
|
|
9
|
|
|
use Canvas\Exception\ServerErrorHttpException; |
10
|
|
|
use Baka\Http\Api\BaseController as BakaBaseController; |
|
|
|
|
11
|
|
|
use Canvas\Dto\ListSchema; |
12
|
|
|
use Canvas\Mapper\ListSchemaMapper; |
13
|
|
|
use Phalcon\Db\Column; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class LanguagesController. |
17
|
|
|
* |
18
|
|
|
* @package Canvas\Api\Controllers |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
class SchemaController extends BakaBaseController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* set objects. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function onConstruct() |
29
|
|
|
{ |
30
|
|
|
$this->model = new SystemModules(); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Overwrite inde schema. |
35
|
|
|
* |
36
|
|
|
* @return Response |
37
|
|
|
*/ |
38
|
|
|
public function index(): Response |
39
|
|
|
{ |
40
|
|
|
return $this->response(['We cant list this apps schema']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Given the slug get the schema. |
45
|
|
|
* |
46
|
|
|
* @param string $slug |
47
|
|
|
* @return Response |
48
|
|
|
*/ |
49
|
|
|
public function getBySlug(string $slug): Response |
50
|
|
|
{ |
51
|
|
|
$schema = SystemModules::getBySlug($slug); |
52
|
|
|
|
53
|
|
|
//add a mapper |
54
|
|
|
$this->dtoConfig->registerMapping(SystemModules::class, ListSchema::class) |
55
|
|
|
->useCustomMapper(new ListSchemaMapper()); |
56
|
|
|
|
57
|
|
|
return $this->response($this->mapper->map($schema, ListSchema::class)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Give the slug we give you the DB schema |
62
|
|
|
* this route is only meant to be run by an admin. |
63
|
|
|
* |
64
|
|
|
* @param string $slug |
65
|
|
|
* @return Response |
66
|
|
|
*/ |
67
|
|
|
public function getModelDescription(string $slug): Response |
68
|
|
|
{ |
69
|
|
|
//none admin users can only edit themselves |
70
|
|
|
if (!$this->userData->hasRole('Default.Admins')) { |
71
|
|
|
throw new ServerErrorHttpException('No route found'); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$schema = SystemModules::getBySlug($slug); |
75
|
|
|
$model = new $schema->model_name; |
76
|
|
|
|
77
|
|
|
$columns = $this->db->describeColumns($model->getSource()); |
78
|
|
|
$structure = []; |
79
|
|
|
$type = null; |
|
|
|
|
80
|
|
|
|
81
|
|
|
foreach ($columns as $column) { |
82
|
|
|
switch ($column->getType()) { |
83
|
|
|
case Column::TYPE_INTEGER: |
84
|
|
|
$structure[$column->getName()] = 'integer'; |
85
|
|
|
break; |
86
|
|
|
case Column::TYPE_BIGINTEGER: |
87
|
|
|
$structure[$column->getName()] = 'long'; |
88
|
|
|
break; |
89
|
|
|
case Column::TYPE_TEXT: |
90
|
|
|
case Column::TYPE_VARCHAR: |
91
|
|
|
case Column::TYPE_CHAR: |
92
|
|
|
$structure[$column->getName()] = 'text'; |
93
|
|
|
break; |
94
|
|
|
case Column::TYPE_DATE: |
95
|
|
|
// We define a format for date structure. |
96
|
|
|
$structure[$column->getName()] = ['date', 'yyyy-MM-dd']; |
97
|
|
|
break; |
98
|
|
|
case Column::TYPE_DATETIME: |
99
|
|
|
// We define a format for datetime structure. |
100
|
|
|
$structure[$column->getName()] = ['date', 'yyyy-MM-dd HH:mm:ss']; |
101
|
|
|
break; |
102
|
|
|
case Column::TYPE_DECIMAL: |
103
|
|
|
$structure[$column->getName()] = 'float'; |
104
|
|
|
break; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($model->hasCustomFields()) { |
109
|
|
|
$structure = array_merge($structure, $model->getCustomFields()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $this->response($structure); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths