Test
This commit is contained in:
parent
c206e0204d
commit
a25ace59fe
2 changed files with 599 additions and 626 deletions
|
@ -67,7 +67,7 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
|
||||||
|
|
||||||
|
|
||||||
var result = $http.post('../server/index.php',
|
var result = $http.post('../server/index.php',
|
||||||
$.param({"token": Identity.getToken(), "task": "image", 'action': 'updateImage', 'id': image.id, 'opt': {'name': image.name,'protected':image.protected, 'visibility':image.visibility}}));
|
$.param({"token": Identity.getToken(), "task": "image", 'action': 'updateImage', 'id': image.id, 'opt': {'name': image.name, 'visibility':image.visibility, 'protected':image.protected}}));
|
||||||
|
|
||||||
// Wait and handle the response
|
// Wait and handle the response
|
||||||
result.then(function (response) {
|
result.then(function (response) {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* File containing the Image Class.
|
|
||||||
*
|
|
||||||
* @version 1.0 Initialisation of this file
|
|
||||||
* @since 1.0 Core application's file
|
|
||||||
*
|
|
||||||
* @author Evan Pisani 'yogg at epsina . com'
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File containing the Image Class.
|
||||||
|
*
|
||||||
|
* @version 1.0 Initialisation of this file
|
||||||
|
* @since 1.0 Core application's file
|
||||||
|
*
|
||||||
|
* @author Evan Pisani 'yogg at epsina . com'
|
||||||
|
*
|
||||||
|
*/
|
||||||
use OpenCloud\Common\Error\BadResponseError;
|
use OpenCloud\Common\Error\BadResponseError;
|
||||||
use OpenCloud\Common\Error\BaseError;
|
use OpenCloud\Common\Error\BaseError;
|
||||||
use OpenCloud\Common\Error\NotImplementedError;
|
use OpenCloud\Common\Error\NotImplementedError;
|
||||||
|
@ -17,12 +17,12 @@ use OpenCloud\Common\Error\UserInputError;
|
||||||
require_once("CoreInterface.php");
|
require_once("CoreInterface.php");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image Class of the back-end application
|
* Image Class of the back-end application
|
||||||
*
|
*
|
||||||
* Management of images
|
* Management of images
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class image implements Core{
|
class image implements Core {
|
||||||
|
|
||||||
/** @var App $app protected, contains the main app object */
|
/** @var App $app protected, contains the main app object */
|
||||||
protected $app;
|
protected $app;
|
||||||
|
@ -37,15 +37,14 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return image Object
|
* @return image Object
|
||||||
*/
|
*/
|
||||||
public function __construct($app){
|
public function __construct($app) {
|
||||||
if(!isset($app)){
|
if (!isset($app)) {
|
||||||
$this->app->setOutput("Error", "Incorrect parameter app");
|
$this->app->setOutput("Error", "Incorrect parameter app");
|
||||||
}
|
}
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->libClass = $app->getLibClass("Image");
|
$this->libClass = $app->getLibClass("Image");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute an action
|
* Execute an action
|
||||||
*
|
*
|
||||||
|
@ -53,8 +52,8 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function action($action){
|
public function action($action) {
|
||||||
$this->{$action.""}();
|
$this->{$action . ""}();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,78 +63,76 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function createImage(){
|
private function createImage() {
|
||||||
$opt = $this->app->getPostParam("opt");
|
$opt = $this->app->getPostParam("opt");
|
||||||
|
|
||||||
if(!isset($opt)){
|
if (!isset($opt)) {
|
||||||
$this->app->setOutput("Error", "Incorrect parameter opt");
|
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try {
|
||||||
$options = Array();
|
$options = Array();
|
||||||
|
|
||||||
// Check the image name
|
// Check the image name
|
||||||
if(isset($opt['name'])){
|
if (isset($opt['name'])) {
|
||||||
$imagesList = $this->listImage();
|
$imagesList = $this->listImage();
|
||||||
if(isset($imagesList)){
|
if (isset($imagesList)) {
|
||||||
foreach($imagesList as $image){
|
foreach ($imagesList as $image) {
|
||||||
if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error
|
if (strcmp($image->name, $opt['name']) == 0) { // if the image name already exists -> error
|
||||||
$this->app->setOutput("Error", "Image name already exists");
|
$this->app->setOutput("Error", "Image name already exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$options['name'] = $opt['name'];
|
$options['name'] = $opt['name'];
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$this->app->setOutput("Error", "Missing parameter 'name' for the new image");
|
$this->app->setOutput("Error", "Missing parameter 'name' for the new image");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check optionals arguments
|
// Check optionals arguments
|
||||||
if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
|
if (isset($opt['id'])) { // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
|
||||||
if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error
|
if ($this->libClass->getImage($opt['id']) != null) { // if the id already exists -> error
|
||||||
$this->app->setOutput("Error", "Image id already exists");
|
$this->app->setOutput("Error", "Image id already exists");
|
||||||
}
|
}
|
||||||
$options['id'] = $opt['id'];
|
$options['id'] = $opt['id'];
|
||||||
}
|
}
|
||||||
if(isset($opt['visibility'])){ // public, private
|
if (isset($opt['visibility'])) { // public, private
|
||||||
$options['visibility'] = $opt['visibility'];
|
$options['visibility'] = $opt['visibility'];
|
||||||
}
|
}
|
||||||
if(isset($opt['tags'])){ // list
|
if (isset($opt['tags'])) { // list
|
||||||
$options['tags'] = $opt['tags'];
|
$options['tags'] = $opt['tags'];
|
||||||
}
|
}
|
||||||
if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker
|
if (isset($opt['containerFormat'])) { // string : ami, ari, aki, bare, ovf, ova, docker
|
||||||
$options['containerFormat'] = $opt['containerFormat'];
|
$options['containerFormat'] = $opt['containerFormat'];
|
||||||
}
|
}
|
||||||
if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso
|
if (isset($opt['diskFormat'])) { // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso
|
||||||
$options['diskFormat'] = $opt['diskFormat'];
|
$options['diskFormat'] = $opt['diskFormat'];
|
||||||
}
|
}
|
||||||
if(isset($opt['minDisk'])){ //int
|
if (isset($opt['minDisk'])) { //int
|
||||||
$options['minDisk'] = $opt['minDisk'];
|
$options['minDisk'] = $opt['minDisk'];
|
||||||
}
|
}
|
||||||
if(isset($opt['minRam'])){ // int
|
if (isset($opt['minRam'])) { // int
|
||||||
$options['minRam'] = $opt['minRam'];
|
$options['minRam'] = $opt['minRam'];
|
||||||
}
|
}
|
||||||
if(isset($opt['protected'])){ // boolean
|
if (isset($opt['protected'])) { // boolean
|
||||||
$options['protected'] = $opt['protected'];
|
$options['protected'] = $opt['protected'];
|
||||||
}
|
}
|
||||||
if(isset($opt['properties'])){ // type dict
|
if (isset($opt['properties'])) { // type dict
|
||||||
$options['properties'] = $opt['properties'];
|
$options['properties'] = $opt['properties'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$image = $this->libClass->createImage($options);
|
$image = $this->libClass->createImage($options);
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,27 +140,26 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function listImage(){
|
private function listImage() {
|
||||||
try{
|
try {
|
||||||
$result = array();
|
$result = array();
|
||||||
$l = $this->libClass->listImages();
|
$l = $this->libClass->listImages();
|
||||||
foreach($l as $tmp){
|
foreach ($l as $tmp) {
|
||||||
$result[] = $tmp;
|
$result[] = $tmp;
|
||||||
}
|
}
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->setOutput("Images", $result);
|
$this->app->setOutput("Images", $result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,31 +169,29 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function detailsImage(){
|
private function detailsImage() {
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
}
|
}
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,56 +205,53 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
private function updateImage() {
|
||||||
private function updateImage(){
|
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
$opt = $this->app->getPostParam("opt");
|
$opt = $this->app->getPostParam("opt");
|
||||||
|
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
} else if (!isset($opt)) {
|
||||||
else if(!isset($opt)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect opt parameter");
|
$this->app->setOutput("Error", "Incorrect opt parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = Array();
|
$options = Array();
|
||||||
|
|
||||||
// Voir vérification des types
|
// Voir vérification des types
|
||||||
if(isset($opt['name'])){ //string
|
if (isset($opt['name'])) { //string
|
||||||
$options['name'] = $opt['name'];
|
$options['name'] = $opt['name'];
|
||||||
}
|
}
|
||||||
if(isset($opt['minDisk'])){ //int
|
if (isset($opt['minDisk'])) { //int
|
||||||
$options['minDisk'] = $opt['minDisk'];
|
$options['minDisk'] = $opt['minDisk'];
|
||||||
}
|
}
|
||||||
if(isset($opt['minRam'])){ // int
|
if (isset($opt['minRam'])) { // int
|
||||||
$options['minRam'] = $opt['minRam'];
|
$options['minRam'] = $opt['minRam'];
|
||||||
}
|
}
|
||||||
if(isset($opt['protected'])){ // boolean
|
if (isset($opt['protected'])) { // boolean
|
||||||
$options['protected'] = $opt['protected'];
|
$options['protected'] = $opt['protected'] == "true" ? true : false;
|
||||||
}
|
}
|
||||||
if(isset($opt['visibility'])){ // public, private
|
if (isset($opt['visibility'])) { // public, private
|
||||||
$options['visibility'] = $opt['visibility'];
|
$options['visibility'] = $opt['visibility'];
|
||||||
}
|
}
|
||||||
if(isset($opt['tags'])){ // list
|
if (isset($opt['tags'])) { // list
|
||||||
$options['tags'] = $opt['tags'];
|
$options['tags'] = $opt['tags'];
|
||||||
}
|
}
|
||||||
$image->update($options);
|
$image->update($options);
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
|
@ -274,28 +265,27 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function deleteImage(){
|
private function deleteImage() {
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $this->libClass->getImage($id);
|
$image = $this->libClass->getImage($id);
|
||||||
if($image == null){ // if the image doesn't exists -> error
|
if ($image == null) { // if the image doesn't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$image->delete();
|
$image->delete();
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,31 +298,29 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function reactivateImage(){
|
private function reactivateImage() {
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect parameter");
|
$this->app->setOutput("Error", "Incorrect parameter");
|
||||||
}
|
} else {
|
||||||
else
|
try {
|
||||||
{
|
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
$image->reactivate();
|
$image->reactivate();
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,30 +333,28 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function desactivateImage(){
|
private function desactivateImage() {
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect parameter");
|
$this->app->setOutput("Error", "Incorrect parameter");
|
||||||
}
|
} else {
|
||||||
else
|
try {
|
||||||
{
|
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$image->deactivate();
|
$image->deactivate();
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,36 +368,34 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function uploadImage(){
|
private function uploadImage() {
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
$file_name = $this->app->getPostParam("file_name");
|
$file_name = $this->app->getPostParam("file_name");
|
||||||
$file = $this->app->getPostParam("file");
|
$file = $this->app->getPostParam("file");
|
||||||
error_log(print_r($file, true), 0);
|
error_log(print_r($file, true), 0);
|
||||||
|
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
} else if (!isset($file_name)) {
|
||||||
else if(!isset($file_name)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect file name parameter");
|
$this->app->setOutput("Error", "Incorrect file name parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$stream = \GuzzleHttp\Psr7\stream_for($file);
|
$stream = \GuzzleHttp\Psr7\stream_for($file);
|
||||||
$image->uploadData($stream);
|
$image->uploadData($stream);
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,29 +408,28 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function downloadImage(){
|
private function downloadImage() {
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
|
|
||||||
if(!isset($id)){
|
if (!isset($id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect id parameter");
|
$this->app->setOutput("Error", "Incorrect id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$stream = $image->downloadData();
|
$stream = $image->downloadData();
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $stream);
|
$this->app->setOutput("Images", $stream);
|
||||||
|
@ -461,41 +444,38 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function addMemberImage(){
|
private function addMemberImage() {
|
||||||
$image_id = $this->app->getPostParam("image_id");
|
$image_id = $this->app->getPostParam("image_id");
|
||||||
$member_id = $this->app->getPostParam("member_id");
|
$member_id = $this->app->getPostParam("member_id");
|
||||||
|
|
||||||
if(!isset($image_id)){
|
if (!isset($image_id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
} else if (!isset($member_id)) {
|
||||||
else if(!isset($member_id)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$member_id = $image->addMember($member_id);
|
$member_id = $image->addMember($member_id);
|
||||||
$this->app->setOutput("Images", $member_id);
|
$this->app->setOutput("Images", $member_id);
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List members of an image
|
* List members of an image
|
||||||
*
|
*
|
||||||
|
@ -503,36 +483,34 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function listMemberImage(){
|
private function listMemberImage() {
|
||||||
$image_id = $this->app->getPostParam("image_id");
|
$image_id = $this->app->getPostParam("image_id");
|
||||||
$member_id = $this->app->getPostParam("member_id");
|
$member_id = $this->app->getPostParam("member_id");
|
||||||
|
|
||||||
if(!isset($image_id)){
|
if (!isset($image_id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
} else if (!isset($member_id)) {
|
||||||
else if(!isset($member_id)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
$image = $service->getImage($image_id);
|
$image = $service->getImage($image_id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$members = $image->listMembers();
|
$members = $image->listMembers();
|
||||||
if($members == null){ // if the image don't exists -> error
|
if ($members == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "No member");
|
$this->app->setOutput("Error", "No member");
|
||||||
}
|
}
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $members);
|
$this->app->setOutput("Images", $members);
|
||||||
|
@ -547,38 +525,36 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function detailMemberImage(){
|
private function detailMemberImage() {
|
||||||
$image_id = $this->app->getPostParam("image_id");
|
$image_id = $this->app->getPostParam("image_id");
|
||||||
$member_id = $this->app->getPostParam("member_id");
|
$member_id = $this->app->getPostParam("member_id");
|
||||||
|
|
||||||
if(!isset($image_id)){
|
if (!isset($image_id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
} else if (!isset($member_id)) {
|
||||||
else if(!isset($member_id)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
$member = $image->getMember($member_id);
|
$member = $image->getMember($member_id);
|
||||||
if($member == null){ // if the member don't exists -> error
|
if ($member == null) { // if the member don't exists -> error
|
||||||
$this->app->setOutput("Error", "Member doesn't exist");
|
$this->app->setOutput("Error", "Member doesn't exist");
|
||||||
}
|
}
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
$this->app->setOutput("Images", $member);
|
$this->app->setOutput("Images", $member);
|
||||||
|
@ -593,38 +569,36 @@ class image implements Core{
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function removeMemberImage(){
|
private function removeMemberImage() {
|
||||||
$image_id = $this->app->getPostParam("image_id");
|
$image_id = $this->app->getPostParam("image_id");
|
||||||
$member_id = $this->app->getPostParam("member_id");
|
$member_id = $this->app->getPostParam("member_id");
|
||||||
|
|
||||||
if(!isset($image_id)){
|
if (!isset($image_id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
} else if (!isset($member_id)) {
|
||||||
else if(!isset($member_id)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$member = $image->getMember($member_id);
|
$member = $image->getMember($member_id);
|
||||||
if($member == null){ // if the image don't exists -> error
|
if ($member == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Member doesn't exist");
|
$this->app->setOutput("Error", "Member doesn't exist");
|
||||||
}
|
}
|
||||||
$member->delete();
|
$member->delete();
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -638,44 +612,43 @@ class image implements Core{
|
||||||
* @param String $status New status for the member
|
* @param String $status New status for the member
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
**/
|
* */
|
||||||
private function updateMemberImage(){
|
private function updateMemberImage() {
|
||||||
$image_id = $this->app->getPostParam("image_id");
|
$image_id = $this->app->getPostParam("image_id");
|
||||||
$member_id = $this->app->getPostParam("member_id");
|
$member_id = $this->app->getPostParam("member_id");
|
||||||
$status = $this->app->getPostParam("status");
|
$status = $this->app->getPostParam("status");
|
||||||
|
|
||||||
if(!isset($image_id)){
|
if (!isset($image_id)) {
|
||||||
$this->app->setOutput("Error", "Incorrect image id parameter");
|
$this->app->setOutput("Error", "Incorrect image id parameter");
|
||||||
}
|
} else if (!isset($member_id)) {
|
||||||
else if(!isset($member_id)){
|
|
||||||
$this->app->setOutput("Error", "Incorrect member id parameter");
|
$this->app->setOutput("Error", "Incorrect member id parameter");
|
||||||
}
|
} else {
|
||||||
else{
|
try {
|
||||||
try{
|
|
||||||
$service = $this->libClass;
|
$service = $this->libClass;
|
||||||
|
|
||||||
$image = $service->getImage($id);
|
$image = $service->getImage($id);
|
||||||
if($image == null){ // if the image don't exists -> error
|
if ($image == null) { // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
$member = $image->getMember($member_id);
|
$member = $image->getMember($member_id);
|
||||||
if($member == null){ // if the member don't exists -> error
|
if ($member == null) { // if the member don't exists -> error
|
||||||
$this->app->setOutput("Error", "Member doesn't exist");
|
$this->app->setOutput("Error", "Member doesn't exist");
|
||||||
}
|
}
|
||||||
$member->updateStatus($status);
|
$member->updateStatus($status);
|
||||||
}catch(BadResponseError $e){
|
} catch (BadResponseError $e) {
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
} catch (UserInputError $e) {
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
} catch (BaseError $e) {
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
} catch (NotImplementedError $e) {
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
} catch (Exception $e) {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue