This commit is contained in:
2020-12-01 17:23:13 -03:00
parent 09e8c226bb
commit 9852a8cbdc
274 changed files with 24706 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
sanitize();
if (post('name') != null) {
$user = Model::factory(\Incoviba\common\User::class)->where('name', post('name'))->findOne();
if ($user === false) {
$user = Model::factory(\Incoviba\common\User::class)->create();
$user->name = post('name');
$user->password(post('password'));
$user->save();
echo 'Created';
}
$role = Model::factory(\Incoviba\common\Role::class)->where('description', 'administrador')->findOne();
if ($role == false) {
$role = Model::factory(\Incoviba\common\Role::class)->create(['description' => 'administrador']);
$role->save();
}
$usrRl = Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne();
if ($usrRl == false) {
$usrRl = Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]);
$usrRl->save();
}
$perm = Model::factory(\Incoviba\common\Permission::class)->where('type', 2)->where('ext_id', $role->id)->where('all', 1)->where('access', 1)->findOne();
if ($perm == false) {
$perm = Model::factory(\Incoviba\common\Permission::class)->create([
'type' => 2,
'ext_id' => $role->id,
'all' => 1,
'access' => 1
]);
$perm->save();
}
header('Location: next_step.php?step=create_admin');
} else {
echo view('install.admin');
}
?>

View File

@ -0,0 +1,36 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
sanitize();
$user = Model::factory(\Incoviba\common\User::class)->where('name', 'guest')->findOne();
if ($user === false) {
$user = Model::factory(\Incoviba\common\User::class)->create(['name' => 'guest']);
$user->save();
}
$role = Model::factory(\Incoviba\common\Role::class)->where('description', 'guest')->findOne();
if ($role === false) {
$role = Model::factory(\Incoviba\common\Role::class)->create(['description' => 'guest']);
$role->save();
}
$usrRl = Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne();
if ($usrRl === false) {
$usrRl = Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]);
$usrRl->save();
}
$locations = Model::factory(\Incoviba\common\Location::class)->where('controller', 'auth')->findMany();
foreach ($locations as $location) {
$permission = Model::factory(\Incoviba\common\Permission::class)->where('type', 2)->where('ext_id', $role->id)->where('access', 1)->where('location', $location->id)->findOne();
if ($permission === false) {
$permission = Model::factory(\Incoviba\common\Permission::class)->create([
'type' => 2,
'ext_id' => $role->id,
'access' => 1,
'location' => $location->id
]);
$permission->save();
}
}
header('Location: next_step.php?step=create_guest');
?>

View File

@ -0,0 +1,128 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
sanitize();
$models = [
'User',
'Location',
'Role',
'UserRole',
'Permission',
'Auth'
];
$location = realpath(dirname(dirname(__DIR__)) . '/src/common');
function extractColumn($table, $info, &$keys, &$foreigns) {
$column = [];
switch ($info[0]) {
case 'string';
$column['type'] = 'VARCHAR';
break;
default:
$column['type'] = strtoupper($info[0]);
}
$column['name'] = '`' . str_replace('$', '', $info[1]) . '`';
if ($column['name'] == '`id`') {
$column['attr']['unsigned'] = 'UNSIGNED';
$column['attr']['autoincrement'] = 'AUTO_INCREMENT';
$keys []= $column['name'];
}
array_shift($info);
array_shift($info);
foreach ($info as $data) {
if (strpos($data, '=') !== false) {
list($attr, $val) = explode('=', $data);
switch ($attr) {
case 'length':
$column['type'] .= '(' . $val . ')';
break;
case 'foreign':
list($ftable, $fk) = explode('.', $val);
$foreigns []= 'fk_' . $table . '_' . $ftable . ' FOREIGN KEY (' . $column['name'] . ') REFERENCES ' . $ftable . '(' . $fk . ')';
$column['attr']['unsigned'] = 'UNSIGNED';
break;
default:
$column['attr'][$attr] = strtoupper($attr . ' ' . $val);
}
} else {
$column['attr'][$data] = strtoupper($data);
}
}
if ($column['type'] == 'VARCHAR') {
$column['type'] .= '(255)';
}
if (!isset($column['attr']['null'])) {
$column['attr']['null'] = 'NOT NULL';
}
$attrs = ['unsigned', 'zerofill', 'null', 'default', 'autoincrement'];
$reordered = [];
foreach ($attrs as $attr) {
if (isset($column['attr'][$attr])) {
$reordered[$attr] = $column['attr'][$attr];
}
}
$column['attr'] = $reordered;
return $column;
}
function columnQuery($column) {
$q = $column['name'] . ' ' . $column['type'];
foreach ($column['attr'] as $attr) {
$q .= ' ' . $attr;
}
return $q;
}
function tableQuery($table, $columns, $keys, $foreigns) {
$q = 'CREATE TABLE `' . $table . '` (' . implode(', ', $columns);
if (count($keys) > 0) {
$q .= ', PRIMARY KEY (' . implode(', ', $keys) . ')';
}
if (count($foreigns) > 0) {
$q .= ', CONSTRAINT ' . implode(', CONSTRAINT ', $foreigns);
}
$q .= ') ENGINE=InnoDB DEFAULT CHARSET=utf8;';
return $q;
}
$cnt = 0;
$queries = [];
foreach ($models as $model) {
$class = '\\Incoviba\\common\\' . $model;
$ref = new ReflectionClass($class);
$table = $ref->getProperty('_table')->getValue();
$comments = explode(PHP_EOL, $ref->getDocComment());
$columns = [];
$keys = [];
$foreigns = [];
foreach ($comments as $comment) {
if (strpos($comment, '@property') === false) {
continue;
}
$info = explode(' ', substr($comment, strpos($comment, '@property') + strlen('@property ')));
$column = extractColumn($table, $info, $keys, $foreigns);
$columns []= columnQuery($column);
}
$q = tableQuery($table, $columns, $keys, $foreigns);
$queries []= $q;
}
try {
\ORM::getDb()->beginTransaction();
foreach ($queries as $q) {
\ORM::getDb()->query($q);
}
\ORM::getDb()->commit();
header('Location: next_step.php?step=create_user_base');
} catch (Exception $e) {
\ORM::getDb()->rollBack();
throw $e;
}
?>

View File

@ -0,0 +1,7 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
sanitize();
echo view('install.end');
?>

7
public/install/index.php Normal file
View File

@ -0,0 +1,7 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
sanitize();
echo view('install.start');
?>

View File

@ -0,0 +1,39 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
$controllers = glob(config('locations.controllers') . '/*.php');
$cnt = 0;
$errors = 0;
foreach ($controllers as $controller) {
$info = pathinfo($controller);
$name = $info['filename'];
$controller = '' . Stringy\Stringy::create($name)->underscored();
$class = '\\App\\Controller\\' . $name;
$ref = new ReflectionClass($class);
$methods = $ref->getMethods(ReflectionMethod::IS_STATIC);
try {
foreach ($methods as $method) {
$data = [
'controller' => $controller,
'action' => $method->name
];
$location = Model::factory(\Incoviba\common\Location::class)->where('controller', $controller)->where('action', $method->name)->findOne();
if ($location !== false) {
continue;
}
$location = Model::factory(\Incoviba\common\Location::class)->create($data);
$location->save();
$cnt ++;
}
} catch (Exception $e) {
d($e);
$errors ++;
}
}
if ($errors == 0) {
header('Location: next_step.php?step=log_locations');
}
?>

View File

@ -0,0 +1,20 @@
<?php
include_once dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
sanitize();
$steps = [
'create_user_base',
'log_locations',
'create_guest',
'create_admin',
'end_install'
];
if (get('step') == null) {
$next = $steps[0];
} else {
$next = $steps[array_search(get('step'), $steps) + 1];
}
header('Location: ' . $next . '.php');
?>