Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/core/actions/config/create-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/actions", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/data", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/views", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/classes", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/init", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/init/routes", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/i18n", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/tests", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

// create empty manifest (from template)
$template = <<<EOT
{
Expand Down
71 changes: 71 additions & 0 deletions packages/core/actions/config/delete-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

list($params, $providers) = eQual::announce([
'description' => 'This is the core_config_delete-controller controller created with core_config_create-controller.',
'response' => [
'charset' => 'utf-8',
'accept-origin' => '*'
],
'params' => [
'package' => [
'description' => 'Name of the package of the controller',
'type' => 'string',
'required' => true
],
'controller_type' => [
'description' => 'Type of controller',
'type' => 'string',
"required" => true,
"selection" => ["do","get"]
],
'controller_name' => [
'description' => 'Name of the controller with the path inside of the package (ex : user_create)',
'type' => 'string',
'required' => true
]
],
'access' => [
'visibility' => 'protected',
'groups' => ['users']
],
'providers' => ['context']
]);
/**
* @var \equal\php\context Context
*/
$context = $providers['context'];

// controller logic goes here
$type = $params['controller_type'];

$package = $params['package'];

if(!file_exists(QN_BASEDIR."/packages/{$package}")) {
throw new Exception('missing_package_dir', QN_ERROR_INVALID_CONFIG);
}

if(strcmp($type,"do") === 0) $subdir = "actions";
else $subdir = "data";

if(!file_exists(QN_BASEDIR."/packages/{$package}/{$subdir}")) {
throw new Exception('missing_classes_dir', QN_ERROR_INVALID_CONFIG);
}

$part = explode("_",$params["controller_name"]);
$controller_name = array_pop($part);
$controller_path = implode("/",$part);

$fullpath = QN_BASEDIR."/packages/{$package}/{$subdir}/{$controller_path}/{$controller_name}.php";

if(!file_exists($fullpath)) {
throw new Exception('controller_does_not_exists', QN_ERROR_INVALID_CONFIG);
}

if(!unlink($fullpath)) {
throw new Exception('io_error', QN_ERROR_UNKNOWN);
}


$context->httpResponse()
->status(204)
->send();
73 changes: 73 additions & 0 deletions packages/core/actions/config/delete-model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

list($params, $providers) = eQual::announce([
'description' => 'This is the core_config_delete-model controller created with core_config_create-controller.',
'response' => [
'charset' => 'utf-8',
'accept-origin' => '*'
],
'params' => [
'package' => [
'description' => 'Name of the package of the new model',
'type' => 'string',
'required' => true
],
'model' => [
'description' => 'Name of the model to be created (must be unique).',
'type' => 'string',
'required' => true
]
],
'access' => [
'visibility' => 'protected',
'groups' => ['users']
],
'providers' => ['context']
]);
/**
* @var \equal\php\context Context
*/
$context = $providers['context'];

// controller logic goes here
$package = $params['package'];

if(!file_exists("packages/{$package}")) {
throw new Exception('missing_package_dir', QN_ERROR_INVALID_CONFIG);
}
if(!file_exists("packages/{$package}/classes")) {
throw new Exception('missing_classes_dir', QN_ERROR_INVALID_CONFIG);
}

$model_path = $params['model'];

$parts = explode("\\", $model_path);

$name = array_pop($parts);


$namespace = implode("\\", $parts);

if(strlen($name) <= 0){
throw new Exception('empty_model_name', QN_ERROR_INVALID_PARAM);
}

if(!ctype_upper(mb_substr($name, 0, 1))){
throw new Exception('broken_naming_convention', QN_ERROR_INVALID_PARAM);
}

// Verification de la non existence du model
$file = QN_BASEDIR."/packages/{$package}/classes/{$model_path}.class.php";

if(!file_exists($file)) {
throw new Exception('model_does_not_exists', QN_ERROR_INVALID_PARAM);
}

if(!unlink($file)) {
throw new Exception('io_error', QN_ERROR_UNKNOWN);
}


$context->httpResponse()
->status(200)
->send();
82 changes: 82 additions & 0 deletions packages/core/actions/config/delete-package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

list($params, $providers) = eQual::announce([
'description' => 'This is the core_config_delete-package controller created with core_config_create-controller.',
'response' => [
'content-type' => 'text/plain',
'charset' => 'UTF-8',
'accept-origin' => '*'
],
'params' => [
'package' => [
'description' => 'Name of the package to be deleted.',
'type' => 'string',
'required' => true
],
/*
'true_delete' => [
'description' => 'enable true deletion of the folder',
'type' => 'boolean',
'default' => false
]
*/
],
'access' => [
'visibility' => 'protected',
'groups' => ['users']
],
'providers' => ['context']
]);
/**
* @var \equal\php\context Context
*/
$context = $providers['context'];

if(strcmp($params['package'],"core")===0) {
throw new Exception('core_is_undeletable', QN_ERROR_INVALID_PARAM);
}

$dir = QN_BASEDIR.'/packages/'.$params['package'];


// controller logic goes here
if(!is_dir($dir)) {
throw new Exception('package_does_not_exists', QN_ERROR_INVALID_PARAM);
}

if(!delTree($dir)) {
throw new Exception('io_error', QN_ERROR_INVALID_PARAM);
}

/*
if($params['true_delete']) {
if(!delTree($dir)) {
throw new Exception('io_error', QN_ERROR_INVALID_PARAM);
}
} else {
if(!is_dir(QN_BASEDIR."/_trash/packages/".$params['package'])) {
if(!mkdir(QN_BASEDIR."/_trash/packages/".$params['package'],0777,true)){
throw new Exception('io_error(mkdir)', QN_ERROR_INVALID_PARAM);
}
}
if(!rename($dir,QN_BASEDIR."/_trash/packages/".$params['package']."/".time())) {
throw new Exception('io_error', QN_ERROR_INVALID_PARAM);
}
}
*/

$context->httpResponse()
->status(201)
->send();


function delTree($dir) {

$files = array_diff(scandir($dir), array('.','..'));

foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}

return rmdir($dir);
}