diff --git a/packages/core/actions/config/create-package.php b/packages/core/actions/config/create-package.php index 24421f274..bc2abb999 100644 --- a/packages/core/actions/config/create-package.php +++ b/packages/core/actions/config/create-package.php @@ -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 = << '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(); \ No newline at end of file diff --git a/packages/core/actions/config/delete-model.php b/packages/core/actions/config/delete-model.php new file mode 100644 index 000000000..6cd20bc7c --- /dev/null +++ b/packages/core/actions/config/delete-model.php @@ -0,0 +1,73 @@ + '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(); \ No newline at end of file diff --git a/packages/core/actions/config/delete-package.php b/packages/core/actions/config/delete-package.php new file mode 100644 index 000000000..30713dac6 --- /dev/null +++ b/packages/core/actions/config/delete-package.php @@ -0,0 +1,82 @@ + '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); +} \ No newline at end of file